自动布局XIB嵌入程序的UIView不上浆父 [英] Auto-layout XIB embedded in programmatic UIView not sizing to parent

查看:126
本文介绍了自动布局XIB嵌入程序的UIView不上浆父的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个XIB文件重新presenting与我与实例化自动布局简单视图[一个NSBundle mainBundle] loadNibNamed:@名] [0] 并添加到编程创建的UIView 通过 addSubView

I have a xib file representing a simple view with auto-layout that I am instantiating with [[NSBundle mainBundle] loadNibNamed:@"name"][0] and adding to a programmatically-created UIView via addSubView.

的问题是,该视图是不伸展,以满足它嵌入在视图的大小;而这似乎是拖欠到在该XIB文件指定的大小。 (我也找不到任何方式在容器中设置限制查看自己在厦门国际银行文件,只有它的子视图。)

The problem is that the view is not stretching to meet the size of the view it is embedded in; rather it appears to be defaulting to the size that was specified in the xib file. (I also can't find any way to set constraints on the container view itself in the xib file, only its subviews.)

也有些奇怪的是,当我旋转的iPad,视图的宽度缩小进一步比例。因此,这显然有线某种程度上,但与错误的初始值。

Also somewhat strangely, when I rotate the iPad, the view's width further shrinks proportionately. So it's clearly wired up somehow, but with the wrong initial values.

连接什么我缺少的得到这个内嵌视图来适合视图层次?

What connection am I missing to get this embedded view to fit the view hierarchy properly?

截图(增加了调试红色发色):

Screenshots (magenta colouring added for debugging):

旋转为纵向后:

After rotating to portrait:

推荐答案

它不调整自身,以填补其新的SuperView的原因是你没有安排为它做。总之,你需要补充的限制,code,加一前一后的两个观点联系起来。

The reason it doesn't resize itself to fill its new superview is that you haven't arranged for it to do that. In short, you need to add constraints, in code, to relate the two views after adding one to the other.

最有可能的,IB设置视图来翻译它的自动尺寸调整掩码的约束。什么时候它被设置为使用自动布局其自动尺寸调整掩码是很难从笔尖来确定。

Most likely, IB set the view to translate its autoresizing mask to constraints. What its autoresizing mask is can be hard to determine from the NIB when it's set to use auto layout.

无论如何,当你将它添加到上海华,自动生成的约束条件维持其目前的框架。当上海华调整大小,他们根据自动尺寸调整面具调整它的大小(可能允许宽度和高度不同,但还没到上海华边缘的距离)。

Anyway, when you add it to the superview, the automatically generated constraints maintain its current frame. When the superview resizes, they resize it according to the autoresizing mask (probably allowing width and height to vary but not the distance to the superview edges).

当你使用自动布局时,应做到以下几点:

When you're using auto layout, you should do the following:


  • 在笔尖或关闭 translatesAutoresizingMaskIntoConstraints 关闭它在code它增加了上海华。其中那些你采取的方法取决于你是否预料到的观点永远不会被添加作为管理其子视图的布局框架视图类的子视图。如果可能,那么你应该把它留在了NIB,让该类决定是否将其关闭。

  • Either turn off translatesAutoresizingMaskIntoConstraints in the NIB or turn it off in the code which adds it to the superview. Which of those approaches you take depends on whether you anticipate that the view will ever be added as a subview of a framework view class that manages the layout of its subviews. If you might, then you should leave it on in the NIB and let that class decide whether to turn it off.

添加以它的父后,加入约束来控制,其视图应该摆开上海华。

After adding the view to its superview, add constraints to the superview which controls where the view should be laid out.

这篇关于自动布局XIB嵌入程序的UIView不上浆父的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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