How to rotate orientation programmatically in Swift?

后端 未结 5 1278
有刺的猬
有刺的猬 2020-12-11 15:53

I tried the next:

UIDevice.currentDevice().setValue(UIInterfaceOrientation.Portrait.rawValue, forKey: \"orientation\")

on

         


        
5条回答
  •  佛祖请我去吃肉
    2020-12-11 16:20

    You can override UIViewController.supportedInterfaceOrientations() instead of triggering rotation in viewWillAppear

    For Xcode 7

    override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
        return UIInterfaceOrientationMask.Landscape
    }
    

    For Xcode 6

    override func supportedInterfaceOrientations() -> Int {
        return Int(UIInterfaceOrientationMask.Landscape.rawValue)
    }
    

    And make sure the desired orientations are enabled in project settings.

提交回复
热议问题