当方向改变时,视图控制器的 iOS 部分变黑 [英] iOS part of viewcontroller goes black when orientation changes
问题描述
当我在特定方向加载时更改视图控制器方向时,屏幕的一部分在底部变为空白.
When I change viewcontroller orientation while it's loading on particular orientation, part of the screen goes blank at the bottom.
重现步骤:
- 在视图控制器中有 tableview(我认为没有必要.可以是任何视图)
- 推送一个新的视图控制器,它也有一个表视图(我认为没有必要.可以是任何视图)一个动作
- 将屏幕从一个方向旋转到另一个方向(纵向到横向或横向到纵向).现在您将能够看到暗部.
- 按返回按钮弹出当前视图控制器
- 现在从一个方向旋转到另一个方向(纵向到横向或横向到纵向).现在您也可以在这里看到黑暗的部分.
viewcontroller 的底部变黑了.
The bottom part of viewcontroller goes black.
我可以复制 10 次中的 7 次.
I am able to reproduce 7 out of 10 times.
仅供参考:
我的 Viewcontroller 只有 tableview,所有单元格都有自动布局约束.试图了解它发生的原因,我想解决它.
My Viewcontroller has only tableview that's all and all cells has autolayout constraints. Trying to understand why it happened and I would like to fix it.
有关重现问题的更多详细信息:
基本上,只有当您将设备保持在倾斜位置并推动或弹出视图控制器并且在页面尝试加载时,您必须更改方向然后问题才会发生时,您才能重现此问题.
Basically you can reproduce this issue only if you hold your device in slanting position and either push or pop a view controller and while the page is trying to load , you have to change the orientation then the issue happens.
(双关语意....大声笑)换句话说,你必须像在方向盘上一样倾斜你的设备:)
(Pun intended.... lol ) In other words ,you have to tilt you device as if you are steering the wheel :).
只有当您将设备用作方向盘时才会发生此问题:)
This issue can only happen if you use your device like a steering wheel :)
推荐答案
在一个视图控制器中(父视图控制器推送新视图控制器)在 viewDidLayoutSubviews 设置框架解决了另一个视图控制器中的问题(子视图控制器,一个被推送的)在 viewWillTransition 设置框架解决了这个问题:) 但我仍然不知道为什么这个问题没有通用的解决方案.
In one view controller(Parent the one that pushes new view controller) setting the frame at viewDidLayoutSubviews solves the issue in another view controller(The child view controller , one that's getting pushed) setting the frame at viewWillTransition fixes the problem :) But still I don't know why there's no universal solution to this problem.
这篇关于当方向改变时,视图控制器的 iOS 部分变黑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!