UIView not autoresizing subview

五迷三道 提交于 2020-01-02 07:36:30

问题


I have a UIView a that has autoresizing subviews enabled. It's size is:

 <UIView: 0x7650180; frame = (0 0; 320 394); clipsToBounds = YES; autoresize = LM+RM+H; layer = <CALayer: 0x7650230>>

I have another UIView b which i added to the view a. View b has flexible width/height. When I add it in, I expect it's height to change to 394, but it remains the same as the in the nib (420):

<UIView: 0x764f720; frame = (0 0; 320 460); autoresize = LM+W+RM+TM+H+BM; layer = <CALayer: 0x764f320>>

What am I doing wrong?

Thanks


回答1:


Autoresizing of subviews works only for subviews already added to a parent view. What should you do:

  1. Create a parent view.
  2. Add subviews.
  3. Set autoresizing masks for them.
  4. Resize the parent view.

Only then you will see that subviews are being autoresizes.

Adding subviews after resize will give no effect.




回答2:


Autoresize only affects subviews when the frame of the parent view changes. If you want your subview to have the same height as the parent view, you'll have to set the height to be equal, either before or after you add it as a subview.



来源:https://stackoverflow.com/questions/16128220/uiview-not-autoresizing-subview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!