开发者

How to get iPhone's reliable orientation

I'm looking for a way to get a reliable iPhone orientation.

The best way I've found so far is calling [[UIDevice currentDevice] orientation]. For some reason, it always returns 0 to me - although I called

[[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/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜