UIView不自动调整子视图 [英] UIView not autoresizing subview

查看:96
本文介绍了UIView不自动调整子视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UIView a 已启用自动调整子视图。它的大小是:

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>>

我有另一个UIView b 到视图 a 。视图 b 具有灵活的宽度/高度。当我添加它,我期望它的高度更改为 394 ,但它保持与nib中的相同( 420 ):

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>>

我做错了什么?

感谢

推荐答案

自动调整子视图的大小只适用于已添加到父视图的子视图。您应该怎么做:

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


  1. 创建父视图。

  2. 添加子视图。
  3. 为他们设置自动调整掩码。

  4. 调整父视图的大小。



<

Only then you will see that subviews are being autoresizes.

调整大小后添加子视图不会产生任何效果。

Adding subviews after resize will give no effect.

这篇关于UIView不自动调整子视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆