Ios 7 自定义 UINavigationController 动画在目标控制器中使用 mapView 失败
Posted
技术标签:
【中文标题】Ios 7 自定义 UINavigationController 动画在目标控制器中使用 mapView 失败【英文标题】:Ios 7 custom UINavigationController animation fails with mapView in destination controller 【发布时间】:2014-03-03 16:24:12 【问题描述】:我在UViewController
inside UINavigationViewController
之间玩弄新的UIViewControllerContextTransitioning
我拥有的和想要实现的很简单,但我在某个地方失败了
我在UIScrollView
中有一个MKMapView
(300px * 60px)。通过单击该地图(无论它在可见滚动的哪个位置),我想转到下一个包含全尺寸 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
...
在destinationViewController 为空的情况下,过渡动画效果很好。但是动画里面的地图真的很奇怪,完全不是我想要的。
Any1 有什么我想念或需要思考的指针吗?
【问题讨论】:
【参考方案1】:我在另一个answer 中写了一篇文章,但请确保您正在设置您的 UINavigationControllerDelegate。
UIViewControllerTransitioningDelegate
用于提供的 控制器,UINavigationControllerDelegate
用于推送 控制器。协议中的委托方法返回您的动画师。
【讨论】:
是的,这就是 m8。自从我发布了 q =) tnx 之后,对 API 有了更多的了解!以上是关于Ios 7 自定义 UINavigationController 动画在目标控制器中使用 mapView 失败的主要内容,如果未能解决你的问题,请参考以下文章