how do get two UITextView's in Interface Build

2019-06-11 22:59发布

问题:

how do get two UITextView's in Interface Builder to align properly when going to landscape orientation?

I have one taking up the upper 1/4 roughly of the screen and the other one below taking up the remaining. Everything is looking good in Portrait.

In landscape however they overlap/don't align properly. I've been trying the resizing masks but haven't seemed to come up with the right combination.

How can I get them to keep themselves aligned properly during orientation changes (and use in iPad too would be good)

EDIT 1 - Should clarify that I have in fact on this screen, from top to bottow:

  • Menu Bar (at top)
  • UITextView with heading (bold text)
  • UITextView with details text

So not sure if this makes any different to the answer. Main point is that even when I play with different settings of auto-sizing I can't seem to get it so that after an orientation change the bottom of the high UITextView is still neatly aligned with the top of the lower one (i.e. rather I seem to get an overlap effect)

EDIT 2 - I put borders around both UITextView and infact they are not overlapping in the Landscape mode, but rather the vertical width of the top UITextView (for the heading) seems to shrink such that it cuts off the 2nd/bottom line of the two line heading.

回答1:

To set your autoresizing mask properly, ask yourself these six questions:

  1. Do I want the height of my view to change when the height of its container changes? If so, enable the vertical spring with the up/down arrows in IB. This is equivalent to setting UIViewAutoresizingFlexibleHeight.

  2. Do I want the distance between the top of my view and the top of its container to change when the height of the container changes? If so, disable the top strut in IB. This is equivalent to setting UIViewAutoresizingFlexibleTopMargin.

  3. Do I want the distance between the bottom of my view and the bottom of its container to change when the height of the container changes? If so, disable the bottom strut in IB. This is equivalent to setting UIViewAutoresizingFlexibleBottomMargin.

  4. Do I want the width of my view to change when the width of its container changes? If so, enable the horizontal spring with the left/right arrows in IB. This is equivalent to setting UIViewAutoresizingFlexibleWidth.

  5. Do I want the distance between the left hand side of my view and the left hand side of its container to change when the width of the container changes? If so, disable the left strut in IB. This is equivalent to setting UIViewAutoresizingFlexibleLeftMargin.

  6. Do I want the distance between the right hand side of my view and the right hand side of its container to change when the width of the container changes? If so, disable the right strut in IB. This is equivalent to setting UIViewAutoresizingFlexibleRightMargin.



回答2:

I have ran into this problem, try re-sizing the textView directly in scrollView delegate scrollViewDidRotate: