【问题标题】:Why don't call method presentationControllerForPresentedViewController of UIViewControllerTransitioningDelegate?为什么不调用 UIViewControllerTransitioningDelegate 的方法presentationControllerForPresentedViewController?
【发布时间】:2014-10-22 09:50:51
【问题描述】:

我想使用自定义 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方法没有调用!

为什么?

【问题讨论】:

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


    【解决方案1】:

    仅当您使用 UIModalPresentationCustom 演示样式呈现视图控制器时才会调用它

    【讨论】:

    • 他正在使用 UIModalPresentationCustom
    • @litso 确实如此。我不知道我是怎么错过的以及为什么我的答案被接受了。有可能作者实现了 UIViewControllerTransitioningDelegate 方法,但不符合这个协议。
    【解决方案2】:

    modalPresentationStyle 而不是modalTransitionStyle 是正确答案:)

    【讨论】:

    • 哇,我一直在使用自定义过渡一段时间,有时事情变得很奇怪,我不知道为什么。有 modalPresentationStyle 和 modalTransitionStyle ...
    • 愿上帝保佑你和你的家人帮助我找到这个愚蠢的错误。
    猜你喜欢
    • 2015-07-01
    • 2018-03-26
    • 2011-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多