SnapKit / Masonry

Harness the power of AutoLayout NSLayoutConstraints with a simplified, chainable and expressive syntax. Supports iOS and OSX Auto Layout
MIT License
18.05k stars 3.14k forks source link

mas_remakeConstraints does not remove all installed constraints #417

Closed iwill closed 7 years ago

iwill commented 7 years ago

New Issue Checklist

🚫 If this template is not filled out your issue will be closed with no comment. 🚫

Issue Info

Info Value
Platform ios
Platform Version 10.2
Masonry Version 1.0.2
Integration Method cocoapods

Issue Description

I need set different constrains for horizontal and vertical orientation by calling mas_remakeConstraints when rotate device.

    [self.viewA mas_remakeConstraints:^(MASConstraintMaker *make) {
        if (isHorizontal) {
            make.left.top.bottom.equalTo(self.view); // left of screen
        }
        else {
            make.left.right.top.equalTo(self.view); // top of screen
        }
    }];
    [self.viewB mas_remakeConstraints:^(MASConstraintMaker *make) {
        if (isHorizontal) {
            make.right.top.bottom.equalTo(self.view);
            make.left.equalTo(self.viewA.mas_right); // right of screen
        }
        else {
            make.left.right.bottom.equalTo(self.view);
            make.top.equalTo(self.viewA.mas_bottom); // bottom of screen
        }
        make.width.height.equalTo(self.viewA);
    }];
    MASAttachKeys(self.view, self.viewA, self.viewB);

It prints autolayout warning when rotate device to horizontal.

[LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
        (1) look at each constraint and try to figure out which you don't expect; 
        (2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<MASLayoutConstraint:0x1566f780 UIView:self.viewB.bottom == UIView:self.view.bottom>",
    "<MASLayoutConstraint:0x1566fc70 UIView:self.viewB.top == UIView:self.viewA.bottom>",
    "<MASLayoutConstraint:0x1566c590 UIView:self.viewB.height == UIView:self.viewA.height>",
    "<MASLayoutConstraint:0x1555c5c0 UIView:self.viewA.top == UIView:self.view.top>",
    "<MASLayoutConstraint:0x1556e3b0 UIView:self.viewA.bottom == UIView:self.view.bottom>",
    "<NSLayoutConstraint:0x15552250 UIView:self.view.height == 320>"
)
robertjpayne commented 7 years ago

@iwill you need to run remakeConstraints on the same view, you currently run it once on viewA then once on viewB which will generate two unique sets of constraints.

magic3584 commented 3 years ago

Same error.