gpt4 book ai didi

ios - 从 UINavigationController 中使用自定义转换关闭 UIViewController 时出现黑屏

转载 作者:可可西里 更新时间:2023-11-01 05:39:54 25 4
gpt4 key购买 nike

我有一个 View Controller FromViewController,我希望它呈现一个带有自定义转换的 ToViewController。我已经为 to- 和 from-transitions 实现了 UIViewControllerAnimatedTransitioning,当我呈现和关闭 ToViewController 时,它都运行良好。

但是,如果我的 FromViewController 包含在 UINavigationController 中,当我关闭 ToViewController 时,我只会看到黑屏。

这是关闭时 UIViewControllerAnimatedTransitioning 中的代码:

- (void)animateTransition:(nonnull id<UIViewControllerContextTransitioning>)transitionContext {
self.toViewController = (ToViewController *)
[transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UINavigationController *navigationController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
self.fromViewController = (FromViewController *)navigationController.topViewController;
self.containerView = transitionContext.containerView;

[self.containerView insertSubview:self.fromViewController.view belowSubview:self.toViewController.view];

// My animations go here

// In the animation completion block I call:
[transitionContext completeTransition:!transitionContext.transitionWasCancelled]; // this is when my screen goes black
}

我检查了该应用程序,似乎 UINavigationControllerFromViewController 在关闭后都不在 View 层次结构中。

最佳答案

我想通了。问题是当我将 View 添加到转换上下文容器 View 时:

 [self.containerView insertSubview:self.fromViewController.view belowSubview:self.toViewController.view];

相反,我需要从导航 Controller 添加 View :

[self.containerView insertSubview:navigationController.view belowSubview:self.toViewController.view];

关于ios - 从 UINavigationController 中使用自定义转换关闭 UIViewController 时出现黑屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47968730/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com