UIKit Known Issues Attempting to set an orientation on UIDevice via setValue:forKey: isn’t supported and no longer works. (93367651)
iOS16 how do I force change orientation, any ideas?
UIKit Known Issues Attempting to set an orientation on UIDevice via setValue:forKey: isn’t supported and no longer works. (93367651)
iOS16 how do I force change orientation, any ideas?
in the Whats new in UIKIt video :
https://developer.apple.com/videos/play/wwdc2022/10068/
they mention UIDevice orientation has gone away. Instead they say use :
i tried to call the method 'attemptRotationToDeviceOrientation' on ios16, and the delegate method 'preferredInterfaceOrientationForPresentation' was called it returned the right value, but nothing happend
Apple released new API which is replaced with setValue:forKey:"orientation". And it's quite easy to use.
iOS apps can now request rotation using [UIWindowScene requestGeometryUpdate:errorHandler:] and providing a UIWindowSceneGeometryPreferencesIOS object containing the desired orientations. (95229615)
https://developer.apple.com/documentation/uikit/uiwindowscene/3975944-requestgeometryupdate/
https://developer.apple.com/documentation/ios-ipados-release-notes/ios-ipados-16-release-notes
this works for me
let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene windowScene?.requestGeometryUpdate(.iOS(interfaceOrientations: .portrait))
But what I cannot get it to do is to honour that rotation change afterwards. I've tried .setNeedsUpdateOfSupportedInterfaceOrientations()
but supportedInterfaceOrientations is ignored.