gpt4 book ai didi

ios - 如何将 Controller 保持在一个方向?

转载 作者:行者123 更新时间:2023-11-28 14:10:08 25 4
gpt4 key购买 nike

我有两个类是 UIViewController 的子类。 PortraitViewControllerLandscapeViewController

这些类的变量 shouldAutorotatesupportedInterfaceOrientationspreferredInterfaceOrientationForPresentation 具有覆盖实现,因此它们可以相应地坚持纵向或横向。

我的应用程序接受纵向和横向模式。

现在,我还有:

  1. ViewController1PortraitViewController
  2. 的子类
  3. ViewController2LandscapeViewController
  4. 的子类

当我显示附加了 UINavigationControllerViewController1 时,它会按预期保持纵向。

当我显示附加了 UINavigationControllerViewController2 时,作为 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/

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