你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> iOS刪除AutoLayout

iOS刪除AutoLayout

編輯:IOS開發綜合

有時候,我們需要動態改變View中AutoLayout裡的某個值,比如移動x值,或者y值,改怎麼辦呢?

 

 

以下用到 ZLLayoutConstraint 是別名 NSLayoutConstraint

typedef NSLayoutConstraint ZLLayoutConstraint;

---------------

刪除所有約束

 

#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];
        }
    }
}

---------------

 

刪除單個約束

 

#pragma mark - remove single constraint
- (void)removeAutoLayout:(ZLLayoutConstraint *)constraint{
    for (ZLLayoutConstraint *constraint in self.superview.constraints) {
        if ([constraint isEqual:constraint]) {
            [self.superview removeConstraint:constraint];
        }
    }
}

 

 


---------------

刪除多個約束

 

#pragma mark - remove constraints www.2cto.com
- (void)removeAutoLayoutConstraints:(NSArray *)constraints{
    for (ZLLayoutConstraint *constraint in constraints) {
        for (ZLLayoutConstraint *superViewConstraint in self.superview.constraints) {
            if ([superViewConstraint isEqual:constraint]) {
                [self.superview removeConstraint:constraint];
            }
        }
    }
}

 

 

 

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved