Disable rotation for View Controller in Navigation Controller

前端 未结 7 868
闹比i
闹比i 2020-12-19 12:57

First of all, this isn\'t a duplicate. I\'ve looked at all of the questions related to this on SO and none of them work for me. Hopefully it\'s just because I\'m new to iOS

7条回答
  •  轮回少年
    2020-12-19 13:12

    For those of you using Swift 2, you can follow Andre's answer, but in step one, use the code below in your AppDelegate.swift:

    class AppDelegate: UIResponder, UIApplicationDelegate {
    
    
    var blockRotation: Bool = false
    
    func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> UIInterfaceOrientationMask {
    
        if (self.blockRotation) {
            print("supportedInterfaceOrientations - PORTRAIT")
            return UIInterfaceOrientationMask.Portrait
        } else {
            print("supportedInterfaceOrientations - ALL")
            return UIInterfaceOrientationMask.All
        }
    }
    

    supportedInterfaceOrientationsForWindow: now returns a UIInterfaceOrientationMask instead of an Int.

提交回复
热议问题