如果是viewControl则AutoLayout适配写在- (void)updateViewConstraints方法中修改约束;
如果是view则AutoLayout适配 则在- (void)updateConstraints方法中修改。
可以直接把视图的约束像拖控件一样拖成属性直接在下面的方法里更改即可
//遍历self.myView控件中的约束,找到NSLayoutAttributeHeight控件高度这个约束关系,然后修改
-(void)updateViewConstraints
{
[superupdateViewConstraints];
NSArray *constrains = self.myView.constraints;
for(NSLayoutConstraint *constraintin constrains){
if(constraint.firstAttribute ==NSLayoutAttributeHeight){
constraint.constant = 50.0;
}
}
}
注意:方法中一定要加上[super updateViewConstraints]
这句话。否则会报错