IOS AutoLayout 遍历修改约束
self.cvv2View.hidden = YES;
self.periodView.hidden = YES;
[self.contentView.constraints enumerateObjectsUsingBlock:^(NSLayoutConstraint *constraint, NSUInteger idx, BOOL *stop)
{
if ((constraint.firstItem ==self.periodView)&&(constraint.firstAttribute == NSLayoutAttributeTop))
{
constraint.constant = 0;
}
else if ((constraint.firstItem ==self.cvv2View)&&(constraint.firstAttribute == NSLayoutAttributeTop))
{
constraint.constant = 0;
}
}];
[self.cvv2View.constraints enumerateObjectsUsingBlock:^(NSLayoutConstraint *constraint, NSUInteger idx, BOOL *stop)
{
if ((constraint.firstItem ==self.cvv2View)&&(constraint.firstAttribute == NSLayoutAttributeHeight))
{
constraint.constant = 0;
}
}];
[self.periodView.constraints enumerateObjectsUsingBlock:^(NSLayoutConstraint *constraint, NSUInteger idx, BOOL *stop)
{
if ((constraint.firstItem ==self.periodView)&&(constraint.firstAttribute == NSLayoutAttributeHeight))
{
constraint.constant = 0;
}
}];
1.并不是所有的时候都是 firstItem 跟 firstAttribute (比如trailing的时候)(firstItem.firstItemAttribute == secondItem.secondItemAttribute * multiplier + constant
)
2.高度的时候自己遍历自己,top buttom trailing的时候是父亲遍历儿子(可以通过xib里面的autolayout分布来回忆)
///////
删除某个约束
-
WS(ws)
for( NSLayoutConstraint * con in self.progressBgView.constraints )
{
if ((con.firstItem == ws.progressBgView)&&(con.firstAttribute == NSLayoutAttributeHeight))
{
[ws.progressBgView removeConstraint:con];
}
}