- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有两个类是 UIViewController
的子类。 PortraitViewController
和 LandscapeViewController
。
这些类的变量 shouldAutorotate
、supportedInterfaceOrientations
和 preferredInterfaceOrientationForPresentation
具有覆盖实现,因此它们可以相应地坚持纵向或横向。
我的应用程序接受纵向和横向模式。
现在,我还有:
ViewController1
是 PortraitViewController
ViewController2
是 LandscapeViewController
当我显示附加了 UINavigationController
的 ViewController1
时,它会按预期保持纵向。
当我显示附加了 UINavigationController
的 ViewController2
时,作为 ViewController1
顶部的模态导航,它会按预期保持横向.
UINavigationController
有一个扩展,它也覆盖了上面提到的变量,但它从 visibleController
参数中读取属性。
但是当我关闭 ViewController2
时,ViewController1
出现在横向中。
如何让 ViewController1
保持纵向模式,而不管我在它上面显示什么?
注意:每次设备处于纵向模式时。
编辑:
这是一个演示项目:https://www.dropbox.com/s/ishe88e1x81nzlp/DemoOrientationApp.zip?dl=0
最佳答案
visibleViewController 是导航堆栈的顶层 View Controller 或从导航 Controller 呈现的 View Controller 。
因此,当您呈现第二个导航 Controller 时,第一个导航 Controller 读取第二个导航 Controller 属性,该属性传回横向 View Controller 的属性。
您需要使用的是 topViewController。这样,设置就限于 View Controller 堆栈。
关于ios - 如何将 Controller 保持在一个方向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52657151/
我是一名优秀的程序员,十分优秀!