Autodetect constraint error with one constraint

I have a sensation with a bunch of labels and buttons. When you click on a button, the image slides off the bottom with controls in it, sort of like a keyboard. It looks like this:

 -----------------------------
|                             |
|  [Button 1] [  Slider 1  ]  |
|                             |
|  [Button 2] [  Slider 2  ]  |
|                             |
 -----------------------------

      

This "keyboard" is created at the very beginning when the view is loaded, and the animation ends by rearranging its vertex from 0 to its incremental content size. This escene only supports landscape mode and it took me a while to keep the "keyboard" on the screen when the device is rotated 180 degrees.

The problem I see appears in any of the following situations:

  • The device rotates 180 degrees.
  • The "keyboard" is called.

This problem is as follows:

Unable to simultaneously satisfy constraints...
.
.
.
.
(
    "<NSLayoutConstraint:0x718c6c0 UIButton:0x717e0d0.centerY == UISlider:0x717d9d0.centerY>",
    "<NSLayoutConstraint:0x7190a00 UIButton:0x717e0d0.centerY == UISlider:0x717d9d0.centerY>"
)

      

The error log is giving me this error twice, once for each set of sliders.

What seems strange to me is that the conflicting constraints are exactly the same. I thought I made a copy and paste error twice, but I haven't.

I'm guessing this is because updateViewConstraints are being called on rotation and also I'm animating, but I can't see why only those constraints are affected as there are a few more in this "keyboard" view.

Anyone and all, this Autolayout is beign rather complicated than the apples that require. In my opinion, of course.

Any ideas?

EDIT: The constraints are set in code, using mostly the visual language format. I'm pretty sure that constraints on controls inside "keyboard" are being added to the "keyboard" view, which is normal.

Just to give it a try, I changed the problematic constraints and added them to the "keyboard" subclass instead, I added them to self.view ("keyboard supervisor"). More errors suddenly appear.

Regardless, I would really like to discuss it, because I still don't know what happened and I was just lucky. I would really like to reveal this.

+3


source to share


2 answers


The fact that the conflicting constraints are exactly the same is actually a mistake. In Auto Layout, you cannot have a limit twice. This will create the error you see above.

You definitely added the constraint twice. You can see this from the memory addresses. You have two different instances NSLayoutConstraint

, 0x718c6c0

and 0x7190a00

. However, each of them refers to the same thing. That the vertical center of centerY

your instance UIButton

0x717e0d0

should be in the middle UISlider

0x717d9d0

.



Your method may have updateConstraints

been called and you haven't checked if the constraint exists yet before adding it again.

+2


source


I don't know if this can help you, but I just used this tutorial to set up constraints on buttons and labels in my application



+1


source







All Articles