简体   繁体   English

从横向启动应用程序时,锁定IOS中的肖像方向

[英]Lock Portrait Orientation in IOS on Application Boot from Landscape

So i've run into a fun little bug. 因此,我遇到了一个有趣的小错误。 I have a UINavigationController with several subviews that it will display that we only want to be viewable in Portrait View. 我有一个带有几个子视图的UINavigationController,它将显示我们只希望在人像视图中可见。 To achieve this we subclassed the UINavigationController and added the following: 为此,我们将UINavigationController子类化,并添加了以下内容:

override func shouldAutorotate() -> Bool {
    return false
}

override func supportedInterfaceOrientations() -> Int {
    return Int(UIInterfaceOrientationMask.Portrait.rawValue)
}

This works great, and the app is locked into Portrait and cannot rotate EXCEPT if the user turns the device sideways and then loads the app from landscape. 这样效果很好,并且如果用户侧向旋转设备,然后从横向加载应用程序,则该应用程序将锁定为“纵向”,并且无法旋转。 The expected outcome was for the device to load in portrait, however it loads in landscape, and won't let the user rotate back to portrait ever. 预期的结果是设备以纵向加载,但是以横向加载,并且永远不会让用户旋转回纵向。

The only way I've been able to replicate this is by loading the app from a device already in landscape mode. 我能够复制此内容的唯一方法是从已经处于横向模式的设备加载应用程序。 Any ideas? 有任何想法吗? There are lots of posts about device orientation, but none I could find talking about on app boot. 关于设备定位的文章很多,但是在应用程序启动时我找不到任何讨论。

删除自动旋转,它应该可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iOS定向问题从横向到纵向 - iOS Orientation issue from landscape to portrait iOS:纵向/横向网格 - iOS: grid in portrait / landscape orientation 如何在iOS应用程序中同时管理横向和纵向方向? - How to manage both landscape & portrait orientation in iOS application? ios iframe只有在方向从纵向更改为横向后才能展开 - ios iframe unscrollable only after orientation change from portrait -> landscape 通过单击 iOS 中的按钮将设备方向从纵向更改为横向 - Change the device orientation from portrait to landscape on a button click in iOS iOS为纵向时返回横向 - iOS return landscape orientation when is Portrait IOS设备方向卡在纵向模式下,没有横向 - IOS Device Orientation Stuck at Portrait mode, no Landscape 纵向应用程序iOS中的风景UIView - Landscape UIView in a Portrait Application iOS 如何在IOS的xamarin.forms中将单个ContentPage的方向从纵向更改为全部(横向/纵向)。 - How to change orientation from Portrait to All (Landscape/Portrait both) for the single ContentPage in xamarin.forms for IOS? 从横向更改为纵向时 Xamarin iOS 应用程序崩溃 - Xamarin iOS app crashes when changing from Landscape orientation to Portrait orientation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM