Update the constant property of a constraint programmatically in Swift?

Solutions Collect From Internet About “Update the constant property of a constraint programmatically in Swift?”

In order to declare an animation, you cannot re-define the constraint and call updateConstraints. You are supposed to change the constant of your constraint and follow the format below:

self.view.layoutIfNeeded()
UIView.animateWithDuration(1, animations: {
    self.sampleConstraint.constant = 20
    self.view.layoutIfNeeded()
})