How to force view controller orientation in iOS 8?

前端 未结 25 2395
太阳男子
太阳男子 2020-11-22 13:11

Before iOS 8, we used below code in conjunction with supportedInterfaceOrientations and shouldAutoRotate delegate methods to force app orie

25条回答
  •  执笔经年
    2020-11-22 13:19

    I have the same problem and waste so many time for it. So now I have my solution. My app setting is just support portrait only.However, some screens into my app need have landscape only.I fix it by have a variable isShouldRotate at AppDelegate. And the function at AppDelegate:

    func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> Int {
        if isShouldRotate == true {
            return Int(UIInterfaceOrientationMask.Landscape.rawValue)
        }
        return Int(UIInterfaceOrientationMask.Portrait.rawValue)
    }
    

    And finally when a ViewControllerA need landscape state. Just do that: before push/present to ViewControllerA assign isShouldRotate to true. Don't forget when pop/dismiss that controller assign isShouldRotate to false at viewWillDisappear.

提交回复
热议问题