How to get iPhone's reliable orientation
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
on the app's didFinishLaunching. In addition, I've heard it provides a non-reliable value if the device is flat.
I've also seen that you can access [[UIApplication sharedApplication] statusBarOrientation], but that always returns me 1.
I will mention that although I can't seem to get right rotation, the views ( created by xibs ) all rotate correctly, but I need to check the rotation in code.Can anybody recommend a reliable way to check this?
Tnx in advance!
EDIT: ok weirdest 开发者_如何学编程bug ever - on some views [UIApplication sharedApplication].statusBarOrientation does work, but on some returns always 1.
If the views are indeed rotating correctly then you can just check the view's controller's orientation with:
viewController.interfaceOrientation
If this is not acceptable in your usage, this seems like a good starting place to use the accelerometer in order to find this information:
http://blog.sallarp.com/iphone-accelerometer-device-orientation/
精彩评论