如何在添加后更改自动布局约束

5
我知道如何使用IBOutlet NSLayoutConstraint * xyz;更改自动布局约束。
我正在使用以下代码进行操作:
使用以下代码添加约束:
NSLayoutConstraint *btnbottomConstraint = [NSLayoutConstraint constraintWithItem: currentview attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeHeight multiplier:1.0f constant:sheight];
        [supperView addConstraint:btnbottomConstraint];

使用这段代码获取约束条件。
NSArray * arrConstarint=btnSubbmit.constraints;
for (NSLayoutConstraint * constraint in arrConstarint)
{
    if (constraint.firstAttribute==NSLayoutAttributeHeight)
    {
        constraint.constant=self.maxHeight;
    }
    else if (constraint.firstAttribute==NSLayoutAttributeWidth)
    {
        constraint.constant=self.maxWidth;
    }
}

当我获取视图的限制时,arrConstarint.count 为0,请帮助我找出错误。提前致谢。
1个回答

2

尝试

[supperView addConstraint:btnbottomConstraint];

to

[currentView addConstraint:btnbottomConstraint];

高度和宽度将被添加到视图中,而不是相对于父视图。如果需要进一步帮助,请告诉我。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接