gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:51:46 26 4
gpt4 key购买 nike

我是 iOS 开发的新手,最近在 iOS 9 中遇到了自定义转换的问题。

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

@implementation MyCustomizedTransitioningDelegate

#pragma mark - UIViewControllerTransitioningDelegate

- (id<UIViewControllerAnimatedTransitioning>)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> is called

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

最佳答案

我遇到了同样的问题。

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

为我修复的是将应用 UIViewControllerTransitioningDelegate 协议(protocol)的对象作为变量实例,以与其保持牢固的关系。

我想是因为它在第一次呈现 View 后就被取消了。

关于iOS 9 自定义转换 - 未调用 animationControllerForDismissedController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34302830/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com