JimmyJammed
JimmyJammed

Reputation: 9698

iOS - How to resize views with auto layout?

I am new to auto layout and need to resize some views when it rotates to landscape.

My view hierarchy from top to bottom is:

  1. Toolbar (user info)
  2. Toolbar (scroll view #1 title)
  3. Scrollview #1
  4. Toolbar (scroll view #2 title)
  5. Scrollview #2

All views are adjacent to each other and when rotated stay in the same layout.

However, I need to shrink both scroll views by a small amount so everything fits onto the screen when in landscape mode.

What is the proper way to do this? I have tried manually changing the scrollview frames in a orientation change method, but the view size doesn't change.

Upvotes: 2

Views: 2830

Answers (1)

rdelmar
rdelmar

Reputation: 104092

  1. Give the toolbars explicit heights.
  2. Pin the top tool bar to top and sides.
  3. Pin bottom scrollView to sides and bottom
  4. Make the height of the 2 scrollViews the same.
  5. Make all of the view have vertical spacing constraints between them (you should get this automatically, if you put them right on top of each other when you drag them in).

This should be sufficient to define every views size and position. When the view gets smaller on rotation, the only thing free to change will be the scroll view heights.

Upvotes: 2

Related Questions