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

5
我希望使用自定义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个回答

10

只有在使用UIModalPresentationCustom呈现样式展示视图控制器时,它才会被调用。


他正在使用UIModalPresentationCustom。 - litso
确实如此。我不知道我怎么会错过那个问题,也不明白为什么我的答案没有被接受。可能是作者实现了UIViewControllerTransitioningDelegate方法,但并没有遵循该协议。 - Silmaril

9

modalPresentationStyle代替modalTransitionStyle是一个正确的答案 :)


1
哇,我已经使用自定义转场一段时间了,有时候会出现奇怪的问题,而我不知道为什么。有modalPresentationStyle和modalTransitionStyle... - Jakub Truhlář
1
愿上帝保佑你和你的家人,因为你帮我找到了这个愚蠢的错误。 - shannoga

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接