简体   繁体   中英

iOS Auto Layout Unable to simultaneously satisfy constraints

My code snippet is as below

    self.sortOptionsViewSmall.hidden = !self.sortOptionsViewSmall.hidden;
    self.sortOptionsView.hidden=YES;
    [UIView animateWithDuration:0.4 animations:^{

        **self.sortViewHeightSmall.constant = (self.sortViewHeightSmall.constant == 0) ? 187 : 0;**
        self.sortViewHeightConstraint.constant = (self.sortViewHeightSmall.constant == 187) ? 187 : 0;
        self.tableViewHeightConstraint.constant = self.sortViewHeightSmall.constant == 0 ? 664 : 477;

        [self.view layoutIfNeeded];
    }];

If I navigate to some other view and navigate back the

self.sortViewHeightSmall.constant = (self.sortViewHeightSmall.constant == 0) ? 187 : 0;

gives me below error

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. 
    (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't 
     understand, refer to the documentation for the UIView property 
     translatesAutoresizingMaskIntoConstraints) 
(
"<NSLayoutConstraint:0x181643e0 V:[SortOptionsView:0x18162970(187)]>",
"<NSLayoutConstraint:0x18162ac0 V:[SortOptionsView:0x18162010(0)]>",
"<NSLayoutConstraint:0x18155170 V:[SortOptionsView:0x18162970]-(0)-    
[UITableView:0xea98e00]>",
"<NSLayoutConstraint:0x181551a0 V:[SortOptionsView:0x18162010]-(0)-
[UITableView:0xea98e00]>",
"<NSLayoutConstraint:0x18155260 V:[UIView:0x181544e0]-(0)-
[SortOptionsView:0x18162010]>",
"<NSLayoutConstraint:0x18155290 V:[UIView:0x181544e0]-(0)-
[SortOptionsView:0x18162970]>"
)

Will attempt to recover by breaking constraint

<NSLayoutConstraint:0x181643e0 V:[SortOptionsView:0x18162970(187)]>

Break on objc_exception_throw to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful. this error.**

I tried to use setTranslatesAutoresizingMaskIntoConstraints:NO but it is not working.

Any help is appreciated.

Check your code. In error stack i see two constraits with conflict:

"<NSLayoutConstraint:0x181643e0 V:[SortOptionsView:0x18162970(187)]>",
"<NSLayoutConstraint:0x18162ac0 V:[SortOptionsView:0x18162010(0)]>",

SortOptionsView can't understand, what will be it height size 187 points or 0? You can resolve this conflict with 2 ways:

  1. delete one constrait;
  2. set priority for each conflict constraits;

I hope i sent you on the right path.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM