Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

重复添加constraint后警告Unable to simultaneously satisfy constraints. #7

Open
FaiChou opened this issue Sep 2, 2016 · 1 comment

Comments

@FaiChou
Copy link

FaiChou commented Sep 2, 2016

code

[self.view addConstraints:[self.view1 constraintsSize:CGSizeMake(50, 30)]];
[self.view addConstraints:[self.view1 constraintsTopInContainer:10.0f]];
[self.view addConstraints:[self.view1 constraintsTopInContainer:20.0f]];

console

2016-09-02 19:53:50.192 FaiChouTest[3223:179657] 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. 
(
    "<NSLayoutConstraint:0x7faad0d452c0 UIView:0x7faad306b8f0.top == UIView:0x7faad3017670.top + 10>",
    "<NSLayoutConstraint:0x7faad0d2daf0 UIView:0x7faad306b8f0.top == UIView:0x7faad3017670.top + 20>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7faad0d2daf0 UIView:0x7faad306b8f0.top == UIView:0x7faad3017670.top + 20>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.

这样会使得添加动画变得困难,我们需要手动移除原先的constraint,再添加之。
我们可以在原封装方法里添加判断。

@FaiChou
Copy link
Author

FaiChou commented Sep 2, 2016

Masonry里对于动画,格外添加了一个方法mas_updateConstraints

I am new to autoLayout.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant