iOS 9自定义过渡-未调用animationControllerForDismissedController [英] iOS 9 custom transition - animationControllerForDismissedController not called

查看:444
本文介绍了iOS 9自定义过渡-未调用animationControllerForDismissedController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am a newbee in iOS development and recently run into this problem with customized transition in iOS 9.

我有一个对象符合UIViewControllerTransitioningDelegate协议并实现了animationControllerForDismissedController,类似于:

I have an object conforms to UIViewControllerTransitioningDelegate protocol and implements animationControllerForDismissedController, something like:

@implementation MyCustomizedTransitioningDelegate

#pragma mark - UIViewControllerTransitioningDelegate

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

@end

触发模态转换的过程类似于:

And the process that triggers the modal transition is something like:

@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也未调用,这在我的应用程序中导致了意外问题. (对不起,我英语不好...)

Since animationControllerForDismissedController method is not called, the MyCustomizedTransitionAnimator is not created, which leads to its animateTransition not called either, which causes unexpected problem in my app. (Sorry for my poor English...)

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

I am also attaching the screenshot of stack trace for both iOS8 & iOS9. In iOS 8, animationControllerForDismissedController is called after the stack trace below.

但是在iOS9中,transitionDidFinish是以某种方式被提前调用的,我想这可能会阻止animationControllerForDismissedController被调用?

But in iOS9, transitionDidFinish is called somehow in advance, which I guess probably prevent animationControllerForDismissedController being called?

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

I was wondering if this is an iOS 9 bug or not. Any explanation or work around solution will be greatly appreciated!

推荐答案

我遇到了同样的问题.

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

I hope this will help someone.

对我来说解决的是使应用UIViewControllerTransitioningDelegate协议的对象作为变量实例与之保持牢固的关系.

What fixed it for me is to make the object which applies UIViewControllerTransitioningDelegate protocol as variable instance to keep strong relationship with it.

我认为是因为第一次提出视图后就将其解雇了.

I think because it gets dismissed after the view is presented first time.

这篇关于iOS 9自定义过渡-未调用animationControllerForDismissedController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆