Pages

02 November, 2023

iOS 17 Force Screen Rotation not working on iPAD only

I have followed all the links on Google and StackOverFlow, unfortunately, I could not find any reliable solution Specifically for iPad devices.


I am using the sample code from Kodeco UISplitViewController. You can download the source code from here and add a UIButton.


I added a Button and added a code for WindowScene RequestGeometryUpdate function.


So, please I need help to Rotate iPad Screen when Pressed on Button. I have attached Error Console Message when pressed on a Button.


Your help will be greatly appreciated.
@IBAction func btnSelector(_ sender: Any) {
self.rotateToLandsScapeDevice()
}

func rotateToLandsScapeDevice(){

let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene
if #available(iOS 16.0, *) {
windowScene?.requestGeometryUpdate(.iOS(interfaceOrientations: .landscapeLeft), errorHandler: { error in
print("Error", error)
})
self.setNeedsUpdateOfSupportedInterfaceOrientations()
} else {
// Fallback on earlier versions
UIDevice.current.setValue(UIInterfaceOrientation.landscapeLeft.rawValue, forKey: "orientation")
UIView.setAnimationsEnabled(true)
}

}



Error Console Message
Error Domain=UISceneErrorDomain Code=101 "The current windowing mode
does not allow for programmatic changes to interface orientation."
UserInfo={NSLocalizedDescription=The current windowing
mode does not allow for programmatic changes to interface orientation.}

No comments:

Post a Comment

Thanks