开发者

iPad device orientation is null?

开发者 https://www.devze.com 2023-01-01 10:47 出处:网络
([UIDevice currentDevice].orientation); using the above code in my app, all i get is 0 (unknown) is there something thats going wrong here? Seems pretty straightforward
([UIDevice currentDevice].orientation);

using the above code in my app, all i get is 0 (unknown)

is there something thats going wrong here? Seems pretty straightforward

edit: more research led me to the problem with using device orientation early in 开发者_如何学Gothe app, which I am doing. However when I instead use interfaceOrientation, it always returns 1 (portrait)


Are you seeing this in the simulator or on the device?

The Simulator seems to always return 0, regardless of it's orientation.

If you're seeing this on the device, have you made sure that you're calling

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

From the documentation:

You must call this method before attempting to get orientation data from the receiver.


How do you know it's null? By logging the value?

The orientation property is a numeric value (enum), so you should make sure to log it as such:

NSLog("%d",[UIDevice currentDevice].orientation);
0

精彩评论

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