自定义缩放过渡不适用于模态演示

时间:2014-08-23 19:19:31

标签: ios objective-c uiviewcontroller presentmodalviewcontroller uiviewanimationtransition

我正在尝试创建缩放过渡。当它用于"推动时,我的工作完全正常。现在我需要为模态转换工作,当然它不能只是一个2分钟的修复。

转换是从一个NavigationController到另一个ViewController。我仍然不明白NavigationControllers键何时指向ViewControllers,他们应该指向实际的viewWillAppear

这完全符合我的要求,但所提供的控制器上的NavigationBar永远不会被调用,-(void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext { UINavigationController *fromNav = (id)[transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; UINavigationController *toNav = (id)[transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; UIViewController<SWZoomTransitionDelegate> *fromVC= (UIViewController<SWZoomTransitionDelegate> *)fromNav.topViewController; UIViewController <SWZoomTransitionDelegate> *toVC = (UIViewController<SWZoomTransitionDelegate> *)toNav.topViewController; UIView * containerView = [transitionContext containerView]; UIView * fromView = [fromVC view]; UIView * toView = [toVC view]; [containerView addSubview:toView]; UIView * zoomFromView = [fromVC viewForZoomTransition]; UIView * zoomToView = [toVC viewForZoomTransition]; UIImageView * animatingImageView = [self initialZoomSnapshotFromView:zoomFromView destinationView:zoomToView]; if ([fromVC respondsToSelector:@selector(initialZoomViewSnapshotFromProposedSnapshot:)]) { animatingImageView = [fromVC initialZoomViewSnapshotFromProposedSnapshot:animatingImageView]; } animatingImageView.frame = [zoomFromView.superview convertRect:zoomFromView.frame toView:containerView]; fromView.alpha = 1; toView.alpha = 0; zoomFromView.alpha = 0; zoomToView.alpha = 0; [containerView addSubview:animatingImageView]; ZoomAnimationBlock animationBlock = nil; if ([fromVC respondsToSelector:@selector(animationBlockForZoomTransition)]) { animationBlock = [fromVC animationBlockForZoomTransition]; } [UIView animateKeyframesWithDuration:self.transitionDuration delay:0 options:self.transitionAnimationOption animations:^{ animatingImageView.frame = [zoomToView.superview convertRect:zoomToView.frame toView:containerView]; fromView.alpha = 0; toView.alpha = 1; if (animationBlock) { animationBlock(animatingImageView,zoomFromView,zoomToView); } } completion:^(BOOL finished) { if ([transitionContext transitionWasCancelled]) { [toView removeFromSuperview]; [transitionContext completeTransition:NO]; zoomFromView.alpha = 1; } else { [fromView removeFromSuperview]; [transitionContext completeTransition:YES]; zoomToView.alpha = 1; } [animatingImageView removeFromSuperview]; }]; } 也不会出现。

请帮帮我。我会尽我所能来回答这个问题!

这是动画方法:

{{1}}

1 个答案:

答案 0 :(得分:0)

我和另一个项目有类似的问题。根据{{​​3}}:

,调用viewWillAppear:绝对是预期的行为
  

因此,当互动转换开始时,UIKit背后的机器实际上将会调出视图,视图将消失,将显示视图控制器,所有你通常习惯的东西控制你的应用程序中发生的事情,因为屏幕上和屏幕外都有。

就我而言,问题是动画师对象在转换过程中被取消分配。我正在设置这样的动画师:

- (id<UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented
                                                                  presentingController:(UIViewController *)presenting
                                                                        sourceController:(UIViewController *)source {

    AGBAnimator *animator = [AGBAnimator new];
    return animator;
}

此对象超出范围并在动画期间取消分配。通过创建strong属性并在从此方法返回之前为其分配animator,问题已得到解决,viewWillAppear:等已成功调用。