【发布时间】:2019-02-20 09:04:58
【问题描述】:
我正在使用 Xcode 9.4。在 .xcodeproj 文件中,在 General 选项卡下,我未选中 Portrait 和 Upside Down 选项。应用程序仍会旋转到这两种模式。请帮我做同样的事情
提前谢谢你。
【问题讨论】:
标签: ios swift ipad device-orientation
我正在使用 Xcode 9.4。在 .xcodeproj 文件中,在 General 选项卡下,我未选中 Portrait 和 Upside Down 选项。应用程序仍会旋转到这两种模式。请帮我做同样的事情
提前谢谢你。
【问题讨论】:
标签: ios swift ipad device-orientation
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
【讨论】: