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.
+1
A:
One of:
- Check the
interfaceOrientation
property of the active view controller. [UIApplication sharedApplication].statusBarOrientation
.[UIDevice currentDevice].orientation
. (You may need to call-beginGeneratingDeviceOrientationNotifications
.)
KennyTM
2010-04-29 15:58:08
+8
A:
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
Paul Lynch
2010-04-29 16:00:20
This helped me a lot. I was using [[UIDevice currentDevice] orientation] but when you started the device Face up it was impossible to tell which way the interface was facing. Using [UIApplication sharedApplication].statusBarOrientation has solved this for me. Thanks a lot.
Daniel Wood
2010-05-04 11:53:46