IOS deletes AutoLayout

Source: Internet
Author: User

IOS deletes AutoLayout

Sometimes, we need to dynamically change a value in AutoLayout in the View, such as moving the x value or y value. What should we do?

 

 

ZLLayoutConstraint is used as the alias NSLayoutConstraint.

Typedef NSLayoutConstraint ZLLayoutConstraint;

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

Delete all constraints

 

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

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

 

Delete a single 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];        }    }}

 

 


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

Delete multiple constraints

 

#pragma mark - remove constraints www.bkjia.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];            }        }    }}

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.