iPhone 屏幕的方向的固定

今天,做一個(gè)項(xiàng)目,本意是首頁是要屏幕方向是固定的portrait,rootViewController是navigationController,不論開啟App之前是橫屏或豎屏,進(jìn)到App就變成portrait.

要在UINavigationController的子類里加

    override var shouldAutorotate: Bool{
        return true
    }
    override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
        return .portrait
    }



    override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
        return .portrait
    }

preferredInterfaceOrientationForPresentation: UIInterfaceOrientation這個(gè)方法在啟動(dòng)時(shí)一直沒有調(diào)用,根據(jù)字面的猜想它只在一個(gè)viewController presentation到下一具viewController時(shí),下一個(gè)viewController會(huì)調(diào)用。

上面這樣設(shè)置會(huì)對(duì)navigationController里所有viewController都有效,如果要對(duì)每個(gè)viewController都有自定義的設(shè)置,請(qǐng)看下面的文章
iOS 橫豎屏切換(控制項(xiàng)目的每一個(gè)ViewController)

最好在func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool里加

        UIApplication.shared.statusBarOrientation = .portrait
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容