我是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
在下面的堆栈跟踪之后调用.
但在iOS9中,transitionDidFinish
提前以某种方式调用,我猜可能会阻止animationControllerForDismissedController
被调用?
我想知道这是不是iOS 9的错误.任何解释或解决方案将不胜感激!
我遇到了同样的问题.
我希望这会对某人有所帮助.
为我修复的是将应用UIViewControllerTransitioningDelegate
协议的对象作为变量实例来保持与它的紧密关系.
我认为因为它在第一次呈现视图后被解雇了.