0

I can't seem to lock certain view controllers in portrait mode. I have several view controllers that just consist of a basic view controller. the following code works to lock them in portrait:

//locking to portrate-----
    override var shouldAutorotate : Bool {
        if (UIDevice.current.orientation == UIDeviceOrientation.landscapeLeft ||
            UIDevice.current.orientation == UIDeviceOrientation.landscapeRight ||
            UIDevice.current.orientation == UIDeviceOrientation.unknown) {
                return false
        }
        else {
            return true
        }
    }
    
    override var supportedInterfaceOrientations : UIInterfaceOrientationMask {
        return [UIInterfaceOrientationMask.portrait ,UIInterfaceOrientationMask.portraitUpsideDown]
    }
    //finished locking-------

However i have some view controllers that are embedded into navigation controllers, and the above code does not work for these. I can't figure out the reasoning for this, any ideas?

kitchen800
  • 73
  • 8
  • 29
  • Check solutions in this thread https://stackoverflow.com/questions/28938660/how-to-lock-orientation-of-one-view-controller-to-portrait-mode-only-in-swift – Shawn Frank Mar 21 '22 at 05:50

0 Answers0