Ipad – Get current orientation of iPad

ipadorientation

In a given event handler (not the "shouldAutorotateToInterfaceOrientation" method) how do I detect the current iPad orientation? I have a text field I have to animate up (when keyboard appears) in the Landscape view, but not in the portrait view and want to know which orientation I'm in to see if the animation is necessary.

Best Answer

Orientation information isn't very consistent, and there are several approaches. If in a view controller, you can use the interfaceOrientation property. From other places you can call:

[[UIDevice currentDevice] orientation]

Alternatively, you can request to receive orientation change notifications:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];

Some people also like to check the status bar orientation:

[UIApplication sharedApplication].statusBarOrientation
Related Topic