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.
The easiest way to get to this, is to use the property interfaceOrientation on your UIViewController. (So most often, just: self. interfaceOrientation will do). Remember: Left orientation is entered by turning your device to the right.
Upside Down: This orientation means you change the orientation of your iOS device 180 degrees. But if you check this checkbox only, you will get the below error message when you run the app. So this checkbox should be used with other orientations such as Portrait or Landscape.
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
I think
[[UIDevice currentDevice] orientation];
is not really reliable. Sometimes it works, sometimes not... In my apps, I use
[[UIApplication sharedApplication]statusBarOrientation];
and it works great!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With