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