Tag: autolayout

自动布局具有dynamic高度子视图的UIScrollView

我遇到了使用自动布局约束的UIScrollView问题。 我有以下视图层次结构,通过IB设置约束: – ScrollView (leading, trailing, bottom and top spaces to superview) — ContainerView (leading, trailing, bottom and top spaces to superview) — ViewA (full width, top of superview) — ViewB (full width, below ViewA) — Button (full width, below ViewB) ViewA和ViewB的初始高度为200点,但点击它可以垂直消耗400点的高度。 ViewA和ViewB通过更新高度约束(从200到400)进行扩展。 这里是相应的片段: if(self.contentVisible) { heightConstraint.constant -= ContentHeight; // + additional View's internal constraints […]

将子视图的X置于自动布局中将引发“未准备好约束”

我有一个自定义的UIView子类正在通过一个笔尖初始化。 在-awakeFromNib ,我创build了一个子视图,并尝试将它置于其超视图中。 [self setInteralView: [[UIView alloc] init]]; [[self internalView] addConstraint: [NSLayoutConstraint constraintWithItem: [self internalView] attribute: NSLayoutAttributeCenterX relatedBy: NSLayoutRelationEqual toItem: self attribute: NSLayoutAttributeCenterX multiplier: 1 constant: 0]]; 这打破了,并导致以下输出: 2013-08-11 17:58:29.628 MyApp[32414:a0b] The view hierarchy is not prepared for the constraint: <NSLayoutConstraint:0xc1dcc80 UIView:0xc132a40.centerX == MyView:0xc1315a0.centerX> When added to a view, the constraint's items must be descendants […]