UIDevice currentDevice "orientation" is always null

According to the title. Calling [[UIDevice currentDevice] BeginGeneratingDeviceOrientationNotifications] has no effect.

DidRotateToInterfaceOrientation events, etc. work fine, but I need to be able to poll the orientation of the device randomly.

How can i fix this?

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

+7
objective-c iphone orientation uidevice
Mar 17 '10 at 10:08
source share
5 answers

The UIDevice concept of orientation is apparently only available on real devices. It seems that the simulator always returns 0 here, regardless of whether the notifications were turned on as the docs suggest. Annoyingly uncomfortable, but there you go.

I believe this works fine on the device itself:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; NSLog(@"orientation: %d", [[UIDevice currentDevice] orientation]); [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]; 
+9
Aug 14 '10 at 18:50
source share

seems like a silly question but not he

beginGeneratingDeviceOrientationNotifications

(lower case b) ...

+2
Aug 02 2018-10-14T00:
source share

If you check [[UIDevice currentDevice] orientation] at - (void)viewDidLoad , you will always get zero.

Check it out in the animated method * - (void) viewDidAppear:(BOOL) *, and you

+1
Nov 12
source share

this is in accordance with iMeMyself, says in the comments above, it is a lot of time, and I think this is the correct answer, so I would like to highlight it here:

 UIDeviceOrientation interfaceOrientation = [UIApplication sharedApplication].statusBarOrientation; if (UIInterfaceOrientationIsLandscape(interfaceOrientation)) { //do stuff here } else if (UIInterfaceOrientationIsPortrait(interfaceOrientation)) { //or do stuff here } 
+1
Aug 13 '13 at 2:29
source share

Wouldn't [[UIDevice currentDevice] orientation] give you the current orientation state? You can verify this in your viewWillAppear method of the view controller that you want to poll.

Edit: In addition, there are various ways to get the current orientation, such as using the statusBarOrientation property in the UIApplication tool or interfaceOrientation in the UIViewcontroller.

0
May 22 '10 at 12:33 a.m.
source share



All Articles