I use this code:
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
to get iPad orientation but it returns UIDeviceOrientationUnknown when I use OpenGL rendering. When I play movies or I display UIViews it return the correct value. Do you know how may I get correct orientation? I don't want to use the accelerometer because I want to know when the device has locked orientation.
Thank you!
There are situations where the accelerometer can’t get an accurate read on the orientation, such as when the device is held flat. You should still be able to get the current orientation using:
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
In iOS 13, the statusBarOrientation
has been deprecated. The new preferred way of getting this orientation is
let orientation = UIApplication.shared.windows.first?.windowScene?.interfaceOrientation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With