我想为我的应用程序添加一个新的方向设置,让用户选择纵向,横向或操作系统设置。我找到了一些需要覆盖UIViewController的解决方案。有一个简单的方法吗?
我想截取并模拟系统的方向改变事件?可能吗?
实现下面的UIApplicationDelegate
方法并根据用户选择的设置返回适当的掩码:
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
// The following conditions are pseudo code to give you an idea
if "userSetting == portrait" {
return .portrait
} else if "userSetting == landscape" {
return .landscape
} else {
return .all
}
}
还要确保Info.plist指定所有方向。