相关疑难解决方法(0)

在以编程方式更改视图维度时,Autolayout似乎无法正常工作

我有一个UITableViewCell的自定义子类,并设置了一些约束.

问题是当我尝试更改一个视图的大小时:

CGRect frm = CGRectMake(0, 0, someValue, 30);
cell.indentView.frame = frm;
Run Code Online (Sandbox Code Playgroud)

依赖于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;
    }
}
Run Code Online (Sandbox Code Playgroud)

iphone uitableview ios autolayout

12
推荐指数
1
解决办法
6709
查看次数

标签 统计

autolayout ×1

ios ×1

iphone ×1

uitableview ×1