shouldAutoRotate not working in swift

supportedinterfaceorientations not working
shouldautorotate not called ios 11
shouldautorotate is not called
preferredinterfaceorientationforpresentation not called
navigationcontrollersupportedinterfaceorientations not called
swift change orientation programmatically
supportedinterfaceorientationsfor not work
supportedinterfaceorientations shouldautorotate

I know if VC has navigationController it should contain some like this. But what about swift? How to able call shouldAutoRotate in VC with navigationController? My navigationControllers has standard class UINavigationController (not custom). I want make shouldAutoRotate false for all my VC except single. As I understood there no another ways to just use "Portrait" and make available to rotate single VC

Put this in your view controllers:

override func shouldAutorotate() -> Bool {

     return false // or true for the VC that allows landscape
}

shouldAutorotate, shouldAutorotate. Returns a Boolean value indicating whether the view controller​'€™s contents should auto rotate. SDKs. iOS 6.0+; Mac Catalyst 13.0+. ios - working - uinavigationcontroller prevent rotation overriding shouldAutorotate not working in Swift 3 (3) I'm trying to prevent rotation on one UIViewController and I can't achieve that.

Swift 3 needs the type to be var and not func:

override var shouldAutorotate: Bool {
    return false
}

Configure ViewController rotation settings in Swift 3 on iOS 10, Prior to iOS 10 and Swift 3, I could use the following code in the an error message saying - Cannot assign to property: 'shouldAutorotate' is a  -(BOOL) shouldAutorotate {return NO;} Your PortraitViewController is ok and I don't know your Storyboard configuration. In your case important thing is you should embedded your target view controller in another new navigation controller, then set it's class to your PortraitViewController and present that navigation modally, like I have done in below image and it's working as expected.

Swift 4

The most effective way I found is to add this extension on a given UIViewController - one that first comes into the view:

extension UINavigationController {

    override open var shouldAutorotate: Bool {
        get {
            if let visibleVC = visibleViewController {
                return visibleVC.shouldAutorotate
            }
            return super.shouldAutorotate
        }
    }

    override open var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation{
        get {
            if let visibleVC = visibleViewController {
                return visibleVC.preferredInterfaceOrientationForPresentation
            }
            return super.preferredInterfaceOrientationForPresentation
        }
    }

    override open var supportedInterfaceOrientations: UIInterfaceOrientationMask{
        get {
            if let visibleVC = visibleViewController {
                return visibleVC.supportedInterfaceOrientations
            }
            return super.supportedInterfaceOrientations
        }
    }

}

Then you need to override the shouldAutorotate function. Add this to your UIViewController class:

override open var shouldAutorotate: Bool {
    return false
}

Any UIViewController you navigate to, you can just override the shouldAutorotate function and set it to whatever you prefer (return true or false).

For any views that appear modally, override supportedInterfaceOrientations:

override open var supportedInterfaceOrientations: UIInterfaceOrientationMask {
    return .all
}

overriding shouldAutorotate not working in Swift 3, I'm trying to prevent rotation on one UIViewController and I can't achieve that. I'm doing something like this: open override var shouldAutorotate: Bool { get  You can override your view controller method shouldAutorotate override func locking orientation does not work on ipad ios 8 swift xcode 6.2 still did not work!

Disable Rotation of UIViewController Embedded Into , We will need to override shouldAutorotate function and return a value of false; Add to Disable Rotation of UIViewController Complete Code Example in Swift. The new supportedInterfaceOrientation: method gets called just fine. The shouldAutorotate method, however, will not fire. I need to do some image swapping on rotate, but I can’t get any indication that a rotation is about to occur. Thanks in advance.

Forcing an orientation in iOS, ios orientation ux swift supportedInterfaceOrientations , and shouldAutorotate . I'd expect to be able to get it working out of the box by simply overriding Setting B 's supported orientations to landscape did not force that  Why not register and get more from Qiita? We will deliver articles that match you By following users and tags, you can catch up information on technical fields that you are interested in as a whole

shouldAutoRotate not called in UIViewController subclass?, I have a UINavigationController (not UIViewController) subclass that implements Package manager will finally receive resources support in Swift 5.3. Swift Streamz Stopped Working on Android Box | Swift Streamz Not Working on Firestick. If Swift Stream is not working on your Android Box, Firestick or any other supported platform you might require to clear the cache. For that you require navigating to Settings -> Apps -> Swift Streamz -> Storage and tap on ‘Clear Cache.’

Comments
  • override func shouldAutorotate() -> Bool gives: Method does not override any method from its superclass. And removing override gives me: Method 'shouldAutorotate()' with Objective-C selector 'shouldAutorotate' conflicts with getter for 'shouldAutorotate' from superclass 'UIViewController' with the same Objective-C selector