码迷,mamicode.com
首页 > 移动开发 > 详细

iOS删除AutoLayout

时间:2014-12-30 19:10:58      阅读:264      评论:0      收藏:0      [点我收藏+]

标签: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>



祝大家愉快!



iOS删除AutoLayout

标签:autolayout   zlautolayout   ios   

原文地址:http://blog.csdn.net/meters_l/article/details/42268521

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!