使用“常规”选项卡,无法锁定iPad应用程序的设备方向

问题描述 投票:0回答:1

我正在使用Xcode 9.4。在.xcodeproj文件中的“常规”选项卡下,我取消选中“纵向”和“倒置”选项。应用程序仍然会旋转到这两种模式。请帮我一样

先感谢您。

ios swift ipad device-orientation
1个回答
0
投票

AppDelegate,如果您旋转设备,请按viewController等。此函数始终调用

func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask
{
    return self.restrictRotation
}

用来:

在AppDelegate中:

var restrictRotation:UIInterfaceOrientationMask = .portrait

&在viewController中调用ViewDidLoad或viewWillAppear方法时。我们将改变如下:

(UIApplication.shared.delegate as! AppDelegate).restrictRotation = .all 

然后将调用AppDelegate上的此方法。

func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask
© www.soinside.com 2019 - 2024. All rights reserved.