Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

As per the title. Calling [[UIDevice currentDevice] BeginGeneratingDeviceOrientationNotifications] has no effect.

DidRotateToInterfaceOrientation etc events are working fine, but I need to be able to poll the device orientation arbitrarily.

How can I fix/do this?

The long story: I have a tab application with a navigation controller on each tab. The root view of tab number one is a graph that goes full screen when the orientation changes to landscape; however this needs to be checked whenever the view appears as the orientation change could have occurred elsewhere, so I was hoping to poll the orientation state whenever this view appears.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
706 views
Welcome To Ask or Share your Answers For Others

1 Answer

UIDevice's notion of orientation seems to be only available on actual devices. The simulator seems to always return 0 here, regardless of whether the notifications have been enabled as the docs suggest. Irritatingly inconvenient, but there you go.

I find this works fine on the actual device:

    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    NSLog(@"orientation: %d", [[UIDevice currentDevice] orientation]);
    [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...