从 UITabBarController 在当前上下文中呈现模态视图控制器后出现黑屏

Black screen after presenting modal view controller in current context from UITabBarController(从 UITabBarController 在当前上下文中呈现模态视图控制器后出现黑屏)

本文介绍了从 UITabBarController 在当前上下文中呈现模态视图控制器后出现黑屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的根视图控制器是一个 UITabBarController.我正在尝试在选项卡栏控制器的视图控制器之一上显示模态视图控制器,但仍允许使用选项卡栏转到不同的选项卡 - 换句话说,我希望模态仅中断该特定标签的流程,而不是整个应用程序.

My root view controller is a UITabBarController. I'm trying to present a modal view controller over one of the tab bar controller's view controllers, but still allow the tab bar to be used to go to a different tab - in other words, I would like for the modal to only interrupt to the flow of that particular tab, not the entire app.

为此,我在情节提要中将呈现视图控制器的呈现样式设置为Over Current Context".我遇到的问题是,在呈现模态视图控制器并选择新选项卡后,呈现视图控制器的视图会从窗口中删除,并且在关闭呈现的视图控制器时不会添加回窗口.关闭视图控制器后,移动到另一个选项卡然后返回,最终将呈现的视图控制器放回窗口中.

To do this, I've set the presenting view controller's presentation style as 'Over Current Context' in storyboard. The problem I'm having is that after presenting the modal view controller and selecting a new tab, the presenting view controller's view is removed from the window, and isn't added back to the window when dismissing the presented view controller. After dismissing the view controller, moving to another tab and then coming back finally puts the presenting view controller back into the window.

我已经在 Xcode 中使用Tabbed"模板重现了我的问题.

I've reproduced my problem using the 'Tabbed' template in Xcode.

呈现模态后 - 我为呈现的视图控制器添加了透明度,以便轻松查看呈现的视图控制器中发生了什么.

After presenting modal - I've added transparency to the presented view controller to easily see what's going on in the presented view controller.

切换到第二个选项卡然后返回 - 呈现视图控制器的视图现在已被删除.

Changing to second tab and then back - the presenting view controller's view has now been removed.

关闭模态框会使呈现视图控制器的视图仍从窗口中移除.转到选项卡 2 并返回会将视图添加回窗口.

Dismissing the modal leaves the presenting view controller with it's view still removed from the window. Going to tab 2 and returning adds the view back to the window.

我希望这是我在情节提要中忽略的一些简单的事情,但事实上我可以在更改选项卡之前呈现模态并查看其背后呈现的视图控制器,这让我认为我的设置正确.

I'm hoping this is something simple I've overlooked in storyboard, but the fact that I can present the modal and see the presented view controller behind it before changing tabs makes me think I have things set up correctly.

推荐答案

我遇到了同样的问题,并且能够通过在呈现之前在呈现视图控制器上设置 self.definesPresentationContext = YES; 来解决它模态VC.您也可以在情节提要中进行设置,该复选框在 Interface Builder 中称为Defines Context".

I had the same issue and was able to solve it by setting self.definesPresentationContext = YES; on the presenting view controller before presenting the modal VC. You can also set this in a storyboard, the checkbox is called "Defines Context" in Interface Builder.

这篇关于从 UITabBarController 在当前上下文中呈现模态视图控制器后出现黑屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:从 UITabBarController 在当前上下文中呈现模态视图控制器后出现黑屏

基础教程推荐