UIViewControllerTransitioningDelegate方法未在iOS 7中调用 [英] UIViewControllerTransitioningDelegate method not called in iOS 7

查看:176
本文介绍了UIViewControllerTransitioningDelegate方法未在iOS 7中调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过实现 UIViewControllerTransitioningDelegate 协议中的方法为模态视图控制器创建了自定义过渡动画。

I have created a custom transition animation for a modal view controller by implementing the methods in the UIViewControllerTransitioningDelegate protocol.

在iOS 8和9中,方法被正常调用并且过渡有效。但是,在iOS 7中, animationControllerForPresentedController:presentsController:sourceController:方法永远不会被调用。 animationControllerForDismissedController:方法仍然被正常调用。

In iOS 8 and 9 the methods are called normally and the transition works. However, in iOS 7, the animationControllerForPresentedController:presentingController:sourceController: method never gets called. The animationControllerForDismissedController: method still gets called normally.

#import "MyModalTransitioningDelegate.h"
#import "MyModalFadeTransition.h"

@implementation MyModalTransitioningDelegate

- (id<UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented
                                                                  presentingController:(UIViewController *)presenting
                                                                      sourceController:(UIViewController *)source
{
    return [[MyModalFadeTransition alloc] init];
}

- (id<UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed
{
    return [[MyModalFadeTransition alloc] init];
}

@end

在模态视图控制器中(即呈现的控制器)我在 -viewDidLoad 方法中有以下内容:

In the modal view controller (i.e. the "presented controller") I have the following in its -viewDidLoad method:

self.modalTransitionDelegate = [[OTModalTransitioningDelegate alloc] init]; // This is a custom strong private property due to `tranisitioningDelegate` being a weak property.
self.transitioningDelegate = self.modalTransitionDelegate;
self.modalPresentationStyle = UIModalPresentationCustom;

设置 modalPresentationStyle 似乎不在任何版本的iOS中都有所不同。没有被调用的方法确实说它在iOS 7中可用,所以我不确定它为什么没有被调用。

Setting the modalPresentationStyle doesn't seem to make any difference in any version of iOS. The method that isn't being called does say that it's available in iOS 7 so I'm not sure why it isn't being called.

模态视图控制器是在呈现视图控制器中显示以下代码:

The modal view controller is being presented with the following code in the presenting view controller:

[self presentViewController:self.modalViewController
                   animated:YES
                 completion:nil];


推荐答案

设置 transitioningDelegate 在呈现视图控制器的初始化程序而不是 viewDidLoad 方法中修复了该问题。

Setting the transitioningDelegate in the presenting view controller's initialiser instead of the viewDidLoad method fixed the issue.

它出现在iOS 7中,视图控制器的转换逻辑在 viewDidLoad 之前调用,但是从iOS 8开始是另一种方式。

It appears in iOS 7 a view controller's transitioning logic is called before viewDidLoad, but is the other way around from iOS 8 onwards.

这篇关于UIViewControllerTransitioningDelegate方法未在iOS 7中调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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