8
在自动布局中将子视图的X居中会引发“未为约束做准备”
我有一个自定义的UIView子类,该子类正在通过笔尖初始化。 在中-awakeFromNib,我正在创建一个子视图,并尝试在其子视图中居中。 [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 …