gpt4 book ai didi

objective-c - 当应用程序在 iOS 8 中启动时,如果设备处于横向方向,如何强制纵向方向

转载 作者:行者123 更新时间:2023-11-30 10:19:18 24 4
gpt4 key购买 nike

我的应用程序允许所有四个方向,但 rootviewcontroller 应该只允许纵向。

我重写了 rootviewcontroller 中的supportedInterfaceOrientations 方法,但是如果应用程序启动时设备处于横向方向,则 View Controller 在横向方向上显示不正确,即使只允许纵向方向。这是 iOS 8 特有的问题。

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

最佳答案

在 View Controller 中:

- (BOOL)shouldAutorotate
{
return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}

Swift 版本:

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

关于objective-c - 当应用程序在 iOS 8 中启动时,如果设备处于横向方向,如何强制纵向方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28142530/

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