Force landscape mode in one ViewController using Swift

后端 未结 19 1250
情书的邮戳
情书的邮戳 2020-12-02 07:44

I am trying to force only one view in my application on landscape mode, I am calling

override func shouldAutorotate() -> Bool {
    print(\"shouldAutoro         


        
19条回答
  •  既然无缘
    2020-12-02 08:17

    Using Swift 2.2

    Try:

    let value = UIInterfaceOrientation.LandscapeLeft.rawValue
    UIDevice.currentDevice().setValue(value, forKey: "orientation")
    

    Followed By:

    UIViewController.attemptRotationToDeviceOrientation()
    

    From Apple's UIViewController Class Reference:

    Some view controllers may want to use app-specific conditions to determine what interface orientations are supported. If your view controller does this, when those conditions change, your app should call this class method. The system immediately attempts to rotate to the new orientation.

    Then, as others have suggested, override the following methods as appropriate:

    override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
        return UIInterfaceOrientationMask.LandscapeLeft
    }
    
    override func shouldAutorotate() -> Bool {
        return true
    }
    

    I was having a similar issue with a signature view and this solved it for me.

提交回复
热议问题