2014-10-22 142 views
5

我想使用自定义的UIPresentationController。 对于它,当我想表明新的场景我把这个代码为什么不调用UIViewControllerTransitioningDelegate方法presentationControllerForPresentedViewController?

UIViewController *cv = [[...]]; 

cv.transitionManager=[[MyTransition alloc] init]; 
cv.transitioningDelegate=actionSheet.transitionManager; 
cv.modalTransitionStyle = UIModalPresentationCustom; 

[self presentViewController:cv animated:YES completion:^{ 

}]; 

我的过渡经理方法:

#pragma mark - UIViewControllerTransitioningDelegate 

- (id <UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source{ 
    return self; 
} 

- (id <UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed{ 
    return self; 
} 

- (id <UIViewControllerInteractiveTransitioning>)interactionControllerForPresentation:(id <UIViewControllerAnimatedTransitioning>)animator{ 
    return nil; 
} 

- (id <UIViewControllerInteractiveTransitioning>)interactionControllerForDismissal:(id <UIViewControllerAnimatedTransitioning>)animator{ 
    return self; 
} 


- (UIPresentationController *)presentationControllerForPresentedViewController:(UIViewController *)presented presentingViewController:(UIViewController *)presenting sourceViewController:(UIViewController *)source { 
    MyPresentationController *presentationController = [[MyPresentationController alloc] initWithPresentedViewController:presented presentingViewController:presenting]; 
    return presentationController; 
} 

但该方法presentationControllerForPresentedViewController不来电!

为什么?

回答

9

它只会如果你现在使用UIModalPresentationCustom呈现样式

+0

他使用UIModalPresentationCustom – litso 2015-12-22 23:41:57

+0

@litso确实被调用。我不知道我是如何错过的,为什么我的回答会被接受。作者可能会实现UIViewControllerTransitioningDelegate方法,但不符合此协议。 – Silmaril 2015-12-23 09:15:03

6

modalPresentationStyle代替modalTransitionStyle一个视图控制器是一个正确的答案:)

+1

哇,我一直在使用自定义转换一段时间,有时候事情变得很奇怪,我不知道为什么。有modalPresentationStyle和modalTransitionStyle ... – 2016-03-09 19:05:02