开发者

How to get InterfaceOrientation from iPhone (not DeviceOrientation)?

I've created a modalviewcontroller and all the subviews are created by code. When I'm testing the app, I find a problem. Then main cause of the problem is that an app shouldn't support UpsideDown orientation, but devices may happen to be in that orientation.

If I:

  1. Rotate the device to Portrait orientation, and then to UpsideDown mode and presentModalView, the subviews in modalviewcontroller should appear the same as Portrait orientation.

  2. Rotate the device to Landscape开发者_StackOverflow orientation, and then to UpsideDown mode and presentModalView, the subviews should be treated differently.

The above situation tells me that I should create subviews in modalviewcontroller according to previous InterfaceOrientation.

The problem is: How to get the previous screen's InterfaceOrientation? Getting the device orientation won't do any help in this situation.

PS: I'm writing a lib, I may give my users the interface to send me the "toInterfaceOrientation" from -willRotateToInterfaceOrientation:duration: but are there any ideas about how to get the orientation in my code?


In any UIViewController you can access the property interfaceOrientation like this:

if (self.interfaceOrientation == UIInterfaceOrientationPortrait) {
    // do stuff
}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
   return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜