为什么不调用UIViewControllerTransitioningDelegate的方法presentationControllerForPresentedViewController?

时间:2014-10-22 09:50:52

标签: ios objective-c iphone ios8 ios8-extension

我想使用自定义UIPresentationController。 对于它,当我想要显示新场景时,我称之为

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没有调用!

为什么吗

2 个答案:

答案 0 :(得分:10)

仅当您使用UIModalPresentationCustom演示文稿样式

呈现视图控制器时才会调用它

答案 1 :(得分:9)

modalPresentationStyle代替modalTransitionStyle是正确答案:)