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