【发布时间】:2013-01-08 13:07:00
【问题描述】:
我有一个 UITableViewCell 的自定义子类,并设置了一些约束。
问题是当我尝试像这样更改一个视图的大小时:
CGRect frm = CGRectMake(0, 0, someValue, 30);
cell.indentView.frame = frm;
其他依赖于 cell.indentView 宽度的视图根本不动。
可能是什么情况?
此代码将起作用:
// enumerate over all constraints
for (NSLayoutConstraint *constraint in cell.indentView.constraints) {
// find constraint on this view and with 'width' attribute
if (constraint.firstItem == cell.indentView && constraint.firstAttribute == NSLayoutAttributeWidth)
{
// increase width of constraint
constraint.constant = someValue;
break;
}
}
【问题讨论】:
-
AutoLayout 太丑了,让我哭了。编码快乐!
-
+1 到上面的自动布局仇恨者。那是最糟糕的地狱。在一个项目中使用它之前,你需要思考一百次。我最好在某些屏幕上添加几行计算帧的代码。
-
@Rob 最糟糕的是,即使您将部署目标设置为 >= iOS 5,它也感觉像是在自动开启!
标签: iphone ios uitableview autolayout