Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPad orientation returns unknown values

Tags:

ipad

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!

like image 390
Mircea Ispas Avatar asked Nov 10 '10 15:11

Mircea Ispas


2 Answers

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];
like image 162
Jeff Kelley Avatar answered Sep 30 '22 01:09

Jeff Kelley


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

like image 38
Bek Avatar answered Sep 30 '22 02:09

Bek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!