How to Simultaneously Satisfy Constraints - No Constraints in Place

Unable to simultaneously satisfy constraints - No constraints in place

Let's look at these one by one.

"<NSAutoresizingMaskLayoutConstraint:0x84543d0 h=--& v=--& V:[UIView:0xa330270(768)]>"

This is saying view 0xa330270 (A) must be 768 points high.

"<NSLayoutConstraint:0xa338350 V:[UIView:0xa331260]-(-1)-| (Names: '|':UIView:0xa330270 )>"

This is saying view 0xa331260 (B)'s bottom edge must be a gap of -1 from the bottom of A, which is it's superview.

"<NSLayoutConstraint:0xa338390 V:|-(841)-[UIView:0xa331260] (Names: '|':UIView:0xa330270 )>"

This is saying that B's top edge must be a gap of 841 points from the top of its superview, A.

These three things can't all be true - A can't be 768 points high, and contain a subview with a top edge 841 points inset from the top and -1 points inset from the bottom. Where have you defined each of these constraints?

You haven't said what layout you are trying to achieve, but it looks like you might have an autoresizing mask on the superview that is preventing it changing in height when you rotate the device. As far as I know the autoresizing constraints only appear if you have added views programmatically, since a storyboard or xib is either all-autolayout, or not. Unless you are doing something like adding an auto laid out view (loaded from a nib?) to another view from a non-autolayout nib?

Unable to simultaneously satisfy constraints

The error is what it says, and gives quite clear instructions for you to begin debugging. There are two constraints that conflict. Each instructs the Auto Layout runtime to do something that contradicts the other.

If you are creating and adding views programmatically, then chances are Auto Resizing attributes have been automatically translated to Auto Layout constraints.

So, the first thing to try is, with your programmatically created views, disable this by setting:

myProgrammaticView.translatesAutoresizingMaskIntoConstraints = NO;

Unable to simultaneously satisfy constraints with animation

The reason that you're seeing this is because you are activating new (conflicting) constraints before disabling the old ones that are already in effect.

The start of your else block is the problem, you need to disable the others first before setting tennisButtonHiddenConstraint1 and tennisButtonHiddenConstraint2 to active:

    self.tennisButtonBottomAnchor?.isActive = false
self.tennisButtonRightAnchor?.isActive = false
self.tennisButtonHeightAnchor?.isActive = false
self.tennisButtonWidthAnchor?.isActive = false
self.tennisButtonHiddenConstraint1?.isActive = true
self.tennisButtonHiddenConstraint2?.isActive = true

It works on first load because no other constraints have been added yet (so the order doesn't matter).

If in doubt, always set .isActive = false first is my rule of thumb when toggling between sets of constraints.

Unable to simultaneously satisfy constraints. Probably at least one of the constraints

It's incredibly difficult to solve these problems or warnings.

Here is ONE KEY TIP.

You can actually add a name to EVERY! constraint.

Sample Image

Do so.

Make the name clear and obvious like "the top constraint on the second box" or whatever.

You don't have to do every single constraint in the app, just the possibly problem ones in the relevant region.

Before anything else, you have to do that. :/

Note that there is a vast amount of discussions about this on this site, 100s of questions, eg https://stackoverflow.com/a/31833436/294884

Essentially, "your constraints have a minor problem" and specifically you likely have "one too many constraints somewhere" (or more subtly, you have to change the priority on one).

Your first step is the naming trick, to at least find out what the hell constraints Apple is referring to :/


Some suggest this BTW! http://wtfautolayout.com



For this particular question:

In this particular case, of the many, many possible problems, it turns out the OP's problem was the "two constraints" issue:

If you DO have/need two constraints, then ONE of them MUST have a DIFFERENT priority than the other.



Related Topics



Leave a reply



Submit