UINavigationController 中的 UIViewController 未按预期旋转

发布于 2024-11-03 05:59:41 字数 696 浏览 1 评论 0原文

我有一个 UINavigationController,其根 UIViewController 仅支持纵向方向。当用户按下按钮时,第二个 UIViewController 被加载并推入堆栈,这个视图控制器(我们称之为 secondaryViewController)仅支持横向。

通常会发生的情况是界面在转换到 secondaryViewController 期间旋转,但尽管在 secondaryViewController 上调用了 shouldAutorotateToInterfaceOrientation: ,但这种情况不会发生。一旦我在显示第二个视图控制器时手动倾斜设备,它就会按预期旋转,并且当切换回第一个 UIViewController 时,它会按预期旋转回纵向。

为了测试第一个 UIViewController 允许的界面方向是否对进程有任何影响,我设置了 return YES;然而,对于那里的所有接口,问题仍然存在。我还阅读了有关该主题的技术问答,但是根据此文档,一切都应该没问题,UINavigationController 是窗口的唯一子视图。

我完全以编程方式创建了 secondaryViewController (覆盖 loadView),并且这个特殊情况之前在其他应用程序中工作过。有人知道我可能做错了什么吗?

I have a UINavigationController who's root UIViewController only supports Portrait orientation. When the user presses a button a second UIViewController gets loaded and pushed onto the stack, this view controller, let's call it secondViewController, only supports landscape orientation.

Usually what would happen is that the interface rotates during the transition to secondViewController, but this doesn't happen despite shouldAutorotateToInterfaceOrientation: getting called on secondViewController. Once I tilt the device manually when secondViewController is displayed it rotates as expected and when switching back to the first UIViewController it rotates back to portrait as it should.

To test whether the allowed interface Orientations of the first UIViewController have any influence on the process I set a return YES; for all the interfaces there, however, the problem persisted. I also read the technical Q&A on the subject but according to this doc everything should be fine, the UINavigationController is the only subview of the window.

I create secondViewController completely programmatically (overwriting of loadView) and had this particular case working before in other apps. Does anybody have an idea what I might be doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌梦深 2024-11-10 05:59:41

显然,更改不会自动发生,以下给出了必要的“推动”:

- (void) viewWillAppear:(BOOL)animated {
    [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];
}

Apparently the change doesn't happen automatically, the following gives the neccessary "push":

- (void) viewWillAppear:(BOOL)animated {
    [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文