I have an app with a tab bar, and nav controllers in each tab. When user shakes the device, a UIImageView
appears as a child view in the nav controller. But the UIImageView
must contain a special image, depending on the device's current orientation.
If I write just
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation) if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) { //Code } else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight||interfaceOrientation == UIInterfaceOrientationLandscapeLeft) { //Code } }
The view just goes crazy if user rotated the device before shaking.
Is there a method to get iPhones current orientation?
To adjust the screen rotation settings: Swipe down from the top of the screen to open the Quick settings panel. Look for the screen orientation icon. Depending on your settings, you may need to look for the Portrait, Landscape, or Auto Rotate icon.
Here are macros UIDeviceOrientationIsLandscape
and UIDeviceOrientationIsPortrait
so rather checking separately you can do it like this ...
if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation)) { // code for landscape orientation }
OR
if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation)) { // code for Portrait orientation }
Use the [[UIDevice currentDevice] orientation]
method, as specified here.
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