iOS 转场动画UIViewControllerTransitioningDelegate代理

来源:互联网 发布:淘宝电脑认证入口 编辑:程序博客网 时间:2024/05/20 01:13

最近在看转场动画问题,心中有些疑惑就查了一些信息.

从VC1 present VC2
VC1 就充当presenting view controller
VC2就是presented view controller

UIViewControllerTransitioningDelegate 方法:

  • (nullable id )animationControllerForPresentedController:(UIViewController )presented presentingController:(UIViewController )presenting sourceController:(UIViewController *)source;

  • (nullable id )animationControllerForDismissedController:(UIViewController *)dismissed;

  • (nullable id )interactionControllerForPresentation:(id )animator;

  • (nullable id )interactionControllerForDismissal:(id )animator;

  • (nullable UIPresentationController )presentationControllerForPresentedViewController:(UIViewController )presented presentingViewController:(nullable UIViewController )presenting sourceViewController:(UIViewController )source NS_AVAILABLE_IOS(8_0);

控制器要遵循UIViewControllerTransitioningDelegate代理.看了些demo有些是在VC2中实现这四代理
突然有些疑惑.为什么非要在VC2中实现.API文档也没说在哪个VC中实现.
自己就试着在VC1中去实现,发现效果也是可以实现的.这是心中的疑惑就更大了.

想到present 有presenting 和presented.上面四个代理也类似ForPresentedController

自己就在想四个代理是不是在两个VC中分开实现.事实证明想法是对的.
在VC1 中用

  • (id)interactionControllerForDismissal:(id)animator;

  • (id)interactionControllerForPresentation:(id)animator;

在VC2中用

  • (id)animationControllerForPresentedController:(UIViewController )presented presentingController:(UIViewController )presenting sourceController:(UIViewController *)source;

  • (id)animationControllerForDismissedController:(UIViewController *)dismissed;

PS: 在VC1 和VC2 中遵循代理:
- (instancetype)init
{
self = [super init];
if (self) {
self.transitioningDelegate = self;
self.modalPresentationStyle = UIModalPresentationCustom;
}
return self;
}
总结:
通过自己的实验发现上面的三种方法都可以实现效果.VC1 present VC2 的过程中.是要实现UIViewControllerTransitioningDelegate代理的,不管是在VC1 和VC2 中,可能只是时间略有延迟的问题.
时间原因就写到这,有什么问题,或者更好理解请联系.

0 0
原创粉丝点击