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.animate(withDuration: 1) { self.sampleConstraint.constant = 20 self.view.layoutIfNeeded()}