iOS 16 prevent UIViewController from rotation

Dmitry Zheshinsky

I have an UIViewController that supports all UIInterfaceOrientationMasks But, in one certain case I need to prevent it from rotation Before iOS 16 i was just handling this case like this

override var shouldAutorotate: Bool {
    return !screenRecorderIsActive
}

And everything was working fine After update to iOS 16 my controller keeps rotating and I can't find a way to fix it

Ely

Quoted from the iOS 16 release notes:

[UIViewController shouldAutorotate] has been deprecated is no longer supported. [UIViewController attemptRotationToDeviceOrientation] has been deprecated and replaced with [UIViewController setNeedsUpdateOfSupportedInterfaceOrientations].

Workaround: Apps relying on shouldAutorotate should reflect their preferences using the view controllers supportedInterfaceOrientations. If the supported orientations change, use `-[UIViewController setNeedsUpdateOfSupportedInterface

To implement dynamic supported interface orientations, you can use some code like this:

var screenRecorderIsActive: Bool {
    didSet {
        setNeedsUpdateOfSupportedInterfaceOrientations()
    }
}

override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
    if screenRecorderIsActive {
        return [.landscape] // For example, or a variable representing the orientation when the condition was set
    }
    return [.all]
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

iOS8 - prevent rotation on presenting viewController

Xamarin iOS Prevent rotation for specific viewcontroller

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

How to prevent a UIViewController from being popped out?

iOS switch from a UIView to a UIViewController

ios - Action from UITableView to a UIViewController

Prevent sprite rotation from changing gravity

Call JavaScript function from UIViewController class in iOS

iOS How to pass data from UIViewController to destinationViewController

Prevent Dagger2 component from recreating on screen rotation

CSS prevent rotation transform from affecting :before elements

How to prevent FragmentManager from being destroyed after rotation

Prevent display rotation on iPad

Prevent screen rotation on Android

Return an NSString from UIViewController without delegate iOS7

Sending email from a 'Contact Us' UIViewController iOS 7

IOS Custom sliding UIViewcontroller from left to right and caused segue error

Prevent IOS notification menu from sliding down

Prevent iOS from handling focus event on an <input>

iOS: Prevent touch from propagating up to SKScene

Prevent my iOS 7 app from upgrading

Swift - Prevent back event in UIViewController

Single UIViewController Auto-rotation inside UITabBar

Scenekit Physics - Prevent Rotation on Collision

How to fix Rectangle to it's position to prevent it from randomly flying around the screen after rotation of device?

iOS: Get 'UIViewController' of 'UIButton'

Pop the UIViewController in xamarin ios

iOS UIViewController layout issue

iOS UIViewController inside a UIView