Swift viewing height animation

I have a view sView inside my ViewController. This height has a limitation - I created an IBOutlet for this limitation - sViewHeightConstraint . I want to reduce the height of sView with animation.

I created a function

UIView.animateWithDuration(5.5, animations: { self.sViewHeightConstraint.constant = 50 }) 

The viewing height changes, but I do not see the animation. What am I doing wrong?

+6
source share
1 answer

use layoutIfNeeded()

  view.layoutIfNeeded() // force any pending operations to finish UIView.animateWithDuration(0.2, animations: { () -> Void in self.sViewHeightConstraint.constant = 50 self.view.layoutIfNeeded() }) 

swift 3

 view.layoutIfNeeded() sViewHeightConstraint.constant = 50 UIView.animate(withDuration: 1.0, animations: { self.view.layoutIfNeeded() }) 
+27
source

All Articles