ios - 为什么 UIViewController.UIView 对子 UIViewLabel 的约束抛出错误 "Invalid pairing of layout attributes"?

标签 ios objective-c autolayout

我试图放置一个标签,使标签的顶部位于 UIViewController 下方的 2/3 处。所以我写了这个约束,但它给了我下面的错误。

NSLayoutConstraint *labelTopConstraint = [NSLayoutConstraint constraintWithItem:self.myLabel
                                         attribute:NSLayoutAttributeTop
                                         relatedBy:NSLayoutRelationGreaterThanOrEqual
                                            toItem:self.view
                                         attribute:NSLayoutAttributeHeight
                                        multiplier:0.66
                                          constant:0];

错误:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', 
reason: '*** +[NSLayoutConstraint 
constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:]: 
Invalid pairing of layout attributes'

最佳答案

是的,这很烦人,不是吗?假设您的 View Controller 是屏幕的全高,您可以使用 NSLayoutAttributeBottom 而不是高度,这应该会给您相同的结果。

关于ios - 为什么 UIViewController.UIView 对子 UIViewLabel 的约束抛出错误 "Invalid pairing of layout attributes"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16128372/

相关文章:

objective-c - iPad [opengl-es] 的画图应用程序线条不正确

ios - UIScrollView 分页自动布局和 Storyboard

ios - 奇怪的行为中心按钮自动布局 iOS

ios - 在主视图 Controller 上显示 swrevealviewcontroller

ios - 自定义 View 标签不会改变

objective-c - 计算用户位置与固定位置之间的距离

iphone - xCode动态添加字段

ios - 具有固定大小 View 和自动调整大小 TableView 的自动布局

php - 向 iOS 设备发送数据

ios - 释放iOS中所有自动发布的对象