how do i make a different layout for ipad landscape than ipad portrait?

I cannot figure out how to change the layout when the ipad rotates. I know it can be done because it have seen it happen. I cannot figure it out in 'varying for traits'.

I'm relatively new to Xcode, so this may be simplistic and irrelevant (I'm not up on 'varying for traits'), but can you use the following?


viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {

// code here

}


I have used this to at least resize and re-position a view after a rotation. I know changing the layout is different, but perhaps code for that can be used in the method?

I suggest you study the documentation regarding those varying traits, write a simple app that does nothing but that, and figure it out. Make sure to test it on every device. Some devices have unique behaviours. You'll never get it working by trying to hack it.

My understanding is that it can't be done purely in IB, since both landscape and portrait are the same size class (regular / regular). You would have to design separate sets of constraints, and install/remove/enable/disable as appropriate in code in viewWillTransitionToSize. Disclaimer: I haven't tried to do this recently, so hopefully someone working with iPad layouts more often can confirm.

I really appreciate all the answers; I never would have thought I would get so many responses in just 1 day. specifically, I have a matrix of cards:

8rows x 6columns. when I rotate the ipad I want it to be 6rows x 8 columns. I can't do in just by designing in wR x hR since it applies to both orientations. all I know is that it's possible since I have since it happen on ipad apps. I don't know if I must use viewWillTransition or if there is another way

Another way might be via 'size-class specific views'. Warning...non-trivial concepts ahead 😉


From the Auto Layout Guide - Views with Intrinsic Content Size


Discussion

Interface Builder lets you set size-class specific views, view attributes, and constraints. It allows you to specify different options for three different size classes (Compact, Any, or Regular) for both the width and the height, giving a total of nine different size classes. Four of them correspond to the Final size classes used on devices (Compact-Compact, Compact-Regular, Regular-Compact, and Regular-Regular). The rest are Base size classes, or abstract representations of two or more size classes (Compact-Any, Regular-Any, Any-Compact, Any-Regular, and Any-Any).


When loading the layout for a given size class, the system loads the most-specific settings for that size class. This means that the Any-Any size class defines the default values used by all views. Compact-Any settings affect all views with a compact width, and the Compact-Regular settings are only used for views with a compact width and a regular height. When the view’s size class changes—for example, when an iPhone rotates from portrait to landscape, the system automatically swaps layouts and animates the change.


You can use this feature to create different layouts for the different iPhone orientations. You can also use it to create different iPad and iPhone layouts. The size-class-specific customizations can be as broad or as simple as you want. Of course, the more changes you have, the more complex the storyboard becomes, and the harder it is to design and maintain.


Remember, you need to make sure you have a valid layout for each possible size class, including all the base size classes. As a general rule, it’s usually easiest to pick one layout to be your default layout. Design that layout in the Any-Any size class. Then modify the Final size classes, as needed. Remember, you can both add and remove items in the more specific size classes.

For more complex layouts, you may want to draw out the 9 x 9 grid of size classes before you begin. Fill in the four corners with the layouts for those size classes. The grid then lets you see which constraints are shared across multiple size classes, and helps you find the best combination of layouts and size classes.


For more information on working with size classes, see Debugging Auto Layout.

how do i make a different layout for ipad landscape than ipad portrait?
 
 
Q