标签:autolayout zlautolayout ios
有时候,我们需要动态改变View中AutoLayout里的某个值,比如移动x值,或者y值,改怎么办呢?
下面封装了比较好的方法来删除:摘自 https://github.com/MakeZL/ZLAutoLayout (封装AutoLayout的框架)
以下用到 ZLLayoutConstraint 是别名 NSLayoutConstraint
typedef NSLayoutConstraint ZLLayoutConstraint;
---------------
删除所有约束
<span style="font-size:14px;">#pragma mark - remove view to superView autoLayout - (void)removeAllAutoLayout{ [self removeConstraints:self.constraints]; for (ZLLayoutConstraint *constraint in self.superview.constraints) { if ([constraint.firstItem isEqual:self]) { [self.superview removeConstraint:constraint]; } } }</span>
删除单个约束
<span style="font-size:14px;">#pragma mark - remove single constraint - (void)removeAutoLayout:(ZLLayoutConstraint *)constraint{ for (ZLLayoutConstraint *constraint in self.superview.constraints) { if ([constraint isEqual:constraint]) { [self.superview removeConstraint:constraint]; } } } </span>
---------------
删除多个约束
<span style="font-size:14px;">#pragma mark - remove constraints - (void)removeAutoLayoutConstraints:(NSArray *)constraints{ for (ZLLayoutConstraint *constraint in constraints) { for (ZLLayoutConstraint *superViewConstraint in self.superview.constraints) { if ([superViewConstraint isEqual:constraint]) { [self.superview removeConstraint:constraint]; } } } }</span>
标签:autolayout zlautolayout ios
原文地址:http://blog.csdn.net/meters_l/article/details/42268521