Knodel Knodel - 1 month ago 12
iOS Question

How to check in which position (landscape or portrait) is the iPhone now?

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?

Tim Tim
Answer

Use the [[UIDevice currentDevice] orientation] method, as specified here.