Ios 7 自定义 UINavigationController 动画因目标 Controller 中的 mapView 而失败

标签 ios animation ios7 uiviewcontroller custom-transition

我正在玩弄新的 UIViewControllerContextTransitioningUViewController 之间里面UINavigationViewController

我所拥有的和我想要实现的很简单,但我在某处失败了

我有一个 MKMapView (300px * 60px) 在 UIScrollView 内.通过单击该 map (无论它在可见滚动条的哪个位置),我想转到下一个包含全尺寸 MKMapView 的 View 。 . 我想要的感觉和动画是让用户感觉到他们被吸入 map (有点)=)

到目前为止我已经添加了: <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 为空的情况下效果很好。但是动画中的 map 真的很奇怪,完全不像我想要的那样。

任何人对我错过或需要想到的事情有任何指示吗?

最佳答案

我在另一个answer写了一个帖子,但请确保您正在设置 UINavigationControllerDelegate。

presented Controller 有一个 UIViewControllerTransitioningDelegatepushed Controller 有一个 UINavigationControllerDelegate。协议(protocol)中的委托(delegate)方法返回您的动画师。

关于Ios 7 自定义 UINavigationController 动画因目标 Controller 中的 mapView 而失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22151910/

相关文章:

ios - 如何在IOS 6/7上设置导航栏颜色

ios - Core Audio (iOS 5.1) Reverb2 属性不存在,错误代码-10877

android - 通过 REST API 提供多种图像分辨率

ios - 以表单大小显示弹出 View

Android AlphaAnimation 导致黑框

xcode4 - Xcode 4 和 Xcode 5 一起使用

ios - iOS应用本地化

ios - 在真实设备上测试 PhoneGap 应用程序

javascript - 动画字母很容易?

html - 在 SVG 中绘制的矩形之间插入文本