简体   繁体   中英

iPad - Orientation change and views?

I am trying to have every viewController to display different layout depending on the screen orientation?

What is the best way to move items around?

  • Manually change the location of items (Write code to do that)?
  • Have 2 nibs 1 for each orientation? (Is it even possible to switch nibs?)

Please explain

If it is feasible with your layout, I would make it in code. That way if you have any static elements that are on both layouts you can take advantage of the rotating animation.

If it is not feasible to do this, you can use two use by using a subview. Have 3 xibs. Your main one with any elements on both orientations. Have a view inside this view, and load from two other xibs portrait and landscape layouts.

  1. Yes - use willAnimateRotationToInterfaceOrientation:duration:
  2. You can use loadNibNamed:owner:options: as described here

It would be best to have two different XIB files. Here is some code:

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {

    if (toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {

        //show portrait XIB here

    } else {

        //show landscape XIB here

    }
}

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