如何允许iOS用户设置应用程序的方向

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

我想为我的应用程序添加一个新的方向设置,让用户选择纵向,横向或操作系统设置。我找到了一些需要覆盖UIViewController的解决方案。有一个简单的方法吗?

我想截取并模拟系统的方向改变事件?可能吗?

ios user-interface settings orientation
1个回答
0
投票

实现下面的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指定所有方向。

© www.soinside.com 2019 - 2024. All rights reserved.