Using adaptive layout to move text fields when switching between portrait and landscape

77 Views Asked by At

I am trying to build a simple user form which is adaptive to the screen. Right now I am able to show some text fields vertically. I want to group two fields together so that they will appear next to each other horizontally in the landscape mode.

How can I do that for iOS 8?

2

There are 2 best solutions below

0
On
  1. For different size classes you can have different autolayout setup(constraints) . You will have to select landscape mode from attribute inspector. Then align your text fields, add constraint. It will behave the way you want. Checkout the last 5-6 minutes of Stanford CS193p lecture no 8. Easily you will learn how to do it.

  2. An alternate solution is using collective view which on slight tweaking to FlowLayout will behave the way you need. Hope it helped. I Would prefer to go with this if have not watched that lecture

0
On

Why don't you consider using a CollectionViewController to handle this for you? You can specify that when the screenWidth is greater than a certain number, that two cells are displayed per row rather than only one. If you spend a little time working with the appearance, it will appear as though it is simply a list of fields that do exactly what you've asked for above. You can make it look exactly like your proposed photo above and then move to 2 cells per row when you're in landscape mode. If this sounds like something you want to try but aren't sure how to go about the implementation, let me know and I'll update my answer.