iOS 7自定义UINavigationController动画在目标控制器中使用地图视图失败

3

我正在尝试使用新的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{
   ...
}

}

过渡动画在目标视图控制器为空时效果良好。但是,当地图存在时,动画效果非常奇怪,与我的预期完全不同。请问有人能指点我缺少了什么或需要考虑什么吗?
1个回答

4
我在另一个答案中写了一篇文章,但请确保设置了您的UINavigationControllerDelegate。
对于presented控制器,有一个UIViewControllerTransitioningDelegate,而对于pushed控制器,则有一个UINavigationControllerDelegate。协议中的委托方法返回您的动画器。

是的,这就是它,伙计。自从我发布了问题以来,我对API的理解更深了。谢谢! - Pedroinpeace

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接