Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
172 views
in Technique[技术] by (71.8m points)

ios - 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?

question from:https://stackoverflow.com/questions/2516491/how-to-check-in-which-position-landscape-or-portrait-is-the-iphone-now

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...