当前位置:  开发笔记 > IOS > 正文

iOS 9自定义转换 - 未调用animationControllerForDismissedController

如何解决《iOS9自定义转换-未调用animationControllerForDismissedController》经验,为你挑选了1个好方法。

我是iOS开发中的新手,最近在iOS 9中通过自定义过渡遇到了这个问题.

我有一个对象符合UIViewControllerTransitioningDelegate协议和实现animationControllerForDismissedController,如:

@implementation MyCustomizedTransitioningDelegate

#pragma mark - UIViewControllerTransitioningDelegate

- (id)animationControllerForDismissedController:(UIViewController *)dismissed
{
    MyCustomizedTransitionAnimator *animator = [[MyCustomizedTransitionAnimator alloc] init];
    animator.presenting = NO;
    return animator;
}

@end

触发模态转换的过程如下:

@implementation MyViewController

#pragma mark - Initializers

+ (MyCustomizedTransitioningDelegate *)modalTransitioningDelegateSingletonInstance;
{
    static MyCustomizedTransitioningDelegate *delegateInst = nil;
    static dispatch_once_t onceToken = 0;
    dispatch_once(&onceToken, ^{
        delegateInst = [[MyCustomizedTransitioningDelegate alloc] init];
    });

    return delegateInst;
}

#pragma mark - UIViewController

- (void)dismissViewControllerAnimated:(BOOL)animated completion:(void (^)(void))completion;
{
    [self prepareForDismissViewControllerAnimated:animated completion:&completion];
    [super dismissViewControllerAnimated:animated completion:completion];
}

- (void)prepareForDismissViewControllerAnimated:(BOOL)animated completion:(dispatch_block_t *)completion;
{
    self.presentedViewController.modalPresentationStyle = UIModalPresentationCustom;
    self.presentedViewController.transitioningDelegate = [[self class] modalTransitioningDelegateSingletonInstance];      
}

@end

由于animationControllerForDismissedController没有调用方法,因此MyCustomizedTransitionAnimator不会创建,也animateTransition不会调用它,这会导致我的应用程序出现意外问题.(抱歉我的英语不好......)

我还附上了iOS8和iOS9的堆栈跟踪截图.在iOS 8中,animationControllerForDismissedController在下面的堆栈跟踪之后调用. iOS 8

但在iOS9中,transitionDidFinish提前以某种方式调用,我猜可能会阻止animationControllerForDismissedController被调用? iOS 9:调用<code> transitionDidFinish </ code>

我想知道这是不是iOS 9的错误.任何解释或解决方案将不胜感激!



1> Mejdi Lassid..:

我遇到了同样的问题.

我希望这会对某人有所帮助.

为我修复的是将应用UIViewControllerTransitioningDelegate协议的对象作为变量实例来保持与它的紧密关系.

我认为因为它在第一次呈现视图后被解雇了.

推荐阅读
赛亚兔备_393
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有