narb
narb

Reputation: 988

re-ordering views when switching from portrait to landscape mode (iOS Xcode swift)

I have a user interface (light grey) and image parts (dark grey).

when in portrait mode I'd like to achieve the following:

enter image description here

If I run on an iPhone 4/5 I won't have enough space to show the image. So when rotating to landscape mode I'd like to achieve the following:

enter image description here

Is it something I can achieve through auto layout?

Any pointers to documentation?

I'm new to Xcode/swift. If it's too complicate I might simply force one mode.

Thanks in advance for your advice!

Upvotes: 1

Views: 746

Answers (1)

Marco Boschi
Marco Boschi

Reputation: 2333

To achieve different layout for different orientation (or device) you should use Size Classes and AutoLayout.

In the bottom of your storyboard you should see Any Any, this means that your view controllers will be displayed in the same way on all devices and orientations. If you click on it you can select a new Size Class (the description will help choosing the right one for the desired device and orientation). Then you can change the constraints to arrange the views differently.

Now you will have your views with two sets of constraints: one is applied for the Size Class you have selected, the other will be applied to any other Size Classes.

If you never used constraints to arrange your views here's a tutorial to start with.

Upvotes: 1

Related Questions