我正在尝试使用新的UIViewControllerContextTransitioning
来在UINavigationViewController
内部的UViewController
之间进行转换。
我的目标很简单,但是我在某些地方失败了。我有一个MKMapView
(300px * 60px)位于UIScrollView
中。当用户点击该地图时(无论它在可见滚动条中的位置如何),我希望跳转到下一个包含全尺寸MKMapView
的视图。我想要实现的感觉和动画是让用户感觉自己被吸入地图中(有点像)=)
到目前为止,我已经添加了:<UIViewControllerTransitioningDelegate, UINavigationControllerDelegate>
还有:
-(id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC{
if (operation == UINavigationControllerOperationPush) {
NSLog(@"inside itself");
FixRTransitionAnimator *animator = [FixRTransitionAnimator new];
animator.presenting = YES;
CGRect absoluteframe = [self.mainScrollView convertRect:self.mapView.frame toView:self.view];
animator.mapFrame = absoluteframe;
NSLog(@"the map frame is %@", NSStringFromCGRect(self.mapView.frame));
return animator;
}
else
NSLog(@"nope its outside");
return nil;
}
我有一个与 prepareForSegue
方法相关的问题:
[super prepareForSegue:sender sender:sender];
MapViewController *mapViewController = segue.destinationViewController;
mapViewController.transitioningDelegate = self;
mapViewController.modalPresentationStyle = UIModalPresentationCustom;
最后,我有`FixRTransitionAnimator.m`文件。
-(NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext{
NSLog(@"the time is timed");
return 0.5f;
}
-(void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext{
NSLog(@"we are inside %@",NSStringFromCGRect(self.mapFrame));
UIViewController *fromVController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIViewController *toVController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
CGRect endFrame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width,[UIScreen mainScreen].bounds.size.height);
if (self.presenting) {
fromVController.view.userInteractionEnabled = NO;
[[transitionContext containerView]addSubview:fromVController.view];
[[transitionContext containerView]addSubview:toVController.view];
toVController.view.frame = self.mapFrame;
[UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
fromVController.view.tintAdjustmentMode = UIViewTintAdjustmentModeDimmed;
NSLog(@"inside the animation");
toVController.view.frame = endFrame;
} completion:^(BOOL finished) {
[transitionContext completeTransition:YES];
}];
}else{
...
}
}
过渡动画在目标视图控制器为空时效果良好。但是,当地图存在时,动画效果非常奇怪,与我的预期完全不同。请问有人能指点我缺少了什么或需要考虑什么吗?