我正在UIViewControllerContextTransitioning
内的UViewController
之间使用新的UINavigationViewController
我拥有和想要实现的目标非常简单,但是我在某处失败了
我在MKMapView
中有一个UIScrollView
(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对我想念或需要思考的东西有任何指示吗?
最佳答案
我在另一个answer中写了一篇文章,但请确保您正在设置UINavigationControllerDelegate。
对于提供的控制器,有一个UIViewControllerTransitioningDelegate
,对于推送的控制器,有一个UINavigationControllerDelegate
。协议中的委托方法返回您的动画制作者。