iOS7自定义过渡调用了两次

标签 ios ios7 uitabbarcontroller transitions

我想为 UITabBarController 的选项卡之间的过渡设置动画。 .出于某种原因,此方法来自 UIViewControllerAnimatedTransitioning协议(protocol)被调用两次:

- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext

堆栈跟踪:
enter image description here
紧接着:
enter image description here
还有 - (void)animationEnded:(BOOL)transitionCompleted方法被调用两次。

我不知道为什么。

这是代码:
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext {

    UIView *containerView = [transitionContext containerView];

    UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
    UIViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];

    [toVC.view setTransform:CGAffineTransformMakeTranslation(320, 0)];

    [containerView addSubview:toVC.view];

    [UIView animateWithDuration:0.5 animations:^{
        [toVC.view setTransform:CGAffineTransformIdentity];
        [fromVC.view setTransform:CGAffineTransformMakeTranslation(-320, 0)];
    } completion:^(BOOL finished) {
        [fromVC.view setTransform:CGAffineTransformIdentity];
        [toVC.view setTransform:CGAffineTransformIdentity];
        [transitionContext completeTransition:YES];
    }];

}

最佳答案

对于第一印象,我相信 - (void)animationEnded:(BOOL)transitionCompleted被调用两次,因为你调用了 [transitionContext completeTransition:YES] ,它基于苹果文档:

Call this method after your animations have completed to notify the system that the transition animation is done. The default implementation of this method calls the animator’s animationEnded: method to give it a chance to perform any last minute cleanup.



如果 UIViewControllerAnimatedTransitioning被调用两次然后就可以了。

进一步分析为什么UIViewControllerAnimatedTransitioning被叫了两次我很高兴看到你的animationControllerForPresentedControlleranimationControllerForDismissedController执行。

关于iOS7自定义过渡调用了两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24559139/

相关文章:

ios - 如何使用页面控件在 iOS 中开发部分

swift - TabBar Storyboard如何连接?

iphone - 动态标签栏+iphone sdk

ios - 更改 ViewController 时如何保持 UISlider 状态? ( swift )

ios - 以编程方式添加约束时在 UIView 中启用 AutoLayout

android - 数据显示为空但url在Postman上有效

iOS 应用程序崩溃,因为图像使用了太多 ram

ios - 如何以编程方式在 iOS 中将 PDF 拆分为单独的单页 PDF

ios - 文本字段仅返回 1 个字母或 NULL 的奇怪问题

iphone - 标签栏在导航时隐藏