【发布时间】:2014-08-12 06:37:22
【问题描述】:
我有一个观点,其约束如下。
现在,当我按照以下方式更改约束时:
[cell addConstraint:[NSLayoutConstraint constraintWithItem:cell.view_label
attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual
toItem:cell.view_label.superview
attribute:NSLayoutAttributeLeading multiplier:1.0 constant:60]];
[UIView animateWithDuration:0.2 animations:^{
[cell.view_label updateConstraints];
[cell.view_label.superview updateConstraints];
}];
//不工作
写:
试试这个:(1)查看每个约束并尝试找出你的 不要期待; (2) 找到添加了不需要的约束的代码或 约束并修复它。 (注:如果你看到 NSAutoresizingMaskLayoutConstraints 你不明白的,参考 到 UIView 属性的文档 translatesAutoresizingMaskIntoConstraints) ( "", "")
将尝试通过打破约束来恢复
中断 objc_exception_throw 以在调试器中捕获它。这 UIView 上的 UIConstraintBasedLayoutDebugging 类别中的方法 中列出的也可能有帮助。
帮我解决这个问题
提前致谢
【问题讨论】:
-
更改约束的优先级,1000 的优先级使其成为必需的约束。
-
@tdelepine,感谢您的回答!但我已经尝试过所有优先事项。
-
@user2893370 在 IB 中为约束添加一个出口,并在代码中更改其常量值。
-
@Akhilrajtr,感谢您的回答!它的工作......
标签: ios objective-c uiview autolayout