Black screen after presenting modal view controller in current context from 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 在当前上下文中呈现模态视图控制器后出现黑屏


- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01