简体   繁体   中英

iPhone sdk how to set view orientation with two different views displayed by segmented control

I'm using a segmented control that has two segments.

  • When segment 1 is pressed, I display a view that contains a tableview of which I don't want landscape orientation, only portrait.
  • When segment 2 is pressed, I display a different view of which I want to allow landscape orientation.

So, I'm using the following code:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
   if (self.view == self.myFirstView)
      return false;
   else if (self.view == self.mySecondView)
      return true;
}

This all works nicely, except for the following condition: If the user selects segment 2, and then rotates the phone, the view goes into landscape mode. Then, while still holding the phone in landscape mode, the user presses segment 1. This displays the first view in landscape mode (I only want this view to be displayed in portrait mode).

So, the question is, how do I show the first view, but reset the view orientation to portrait?

Any ideas?

在view1中,获取方向,如果是横向,则将其切换为portratit。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM