最近在看轉場動畫問題,心中有些疑惑就查了一些信息.
從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 中,可能只是時間略有延遲的問題.
時間原因就寫到這,有什麼問題,或者更好理解請聯繫.