RemoveConstraint () does not work

I have a strange problem. I want to change the restriction in certain conditions, but it removeConstraintdoes not work. The restriction is not removed.

Here is the code:

        backButton.translatesAutoresizingMaskIntoConstraints = false
        view.removeConstraint(constLabelTop)
        let constNew = NSLayoutConstraint(item: label, attribute: .CenterY, relatedBy: .Equal, toItem: backButton, attribute: .CenterY,multiplier: 1, constant: 0)
        view.addConstraint(constNew)

A constraint constLabelTopis a constraint that sets the top labela few points higher backButton. Why is this not working?

The new constraint collides with the old, but backButtonreceives compression.

I also tried backButton.removeConstraintand did not work.

+4
source share
1 answer

Try the following:

backButton.translatesAutoresizingMaskIntoConstraints = false
constLabelTop.active = false
NSLayoutConstraint(item: label, attribute: .CenterY, relatedBy: .Equal, toItem: backButton, attribute: .CenterY,multiplier: 1, constant: 0).active = true
self.view.layoutIfNeeded()
+4
source

All Articles