iOS. How to enable and disable rotation on each UIViewController?

后端 未结 8 2122
栀梦
栀梦 2020-12-13 04:10

I have an UIViewController, I want to disable or enable rotation of the screen in different scenarios

Example:

if flag {
   rotateDevice = false
}
e         


        
8条回答
  •  感情败类
    2020-12-13 04:59

    Found this to be by far the simplest implementation, and adaptable to use on specific view controllers. Add this to viewController class, after viewDidLoad()

    override open var shouldAutorotate: Bool {
            return false
        }
    

提交回复
热议问题