First of all you have to drag and drop your constraint into your view controller, to make an outlet. The same way you are doing it with UIImageView
or UITableView
, etc.
Actually, for those who have watched WWDC (2014 I guess), Apple have explained how to animate UI in the proper way.
Firstly, you have to call layoutIfNeeded()
method to make sure that everything on your view have laid out. After you can change your constraint and right after that in your animation block you call layoutIfNeeded()
method to layout your constraint with the new value.
So code should look like that:
view.layoutIfNeeded() // to make sure your view have laid outself.constraint.constant = //change your constant to any valueUIView.animate(withDuration: 1.0) { self.view.layoutIfNeeded() //layout your constraint with the new value}