moonvader moonvader - 5 months ago 18
Swift Question

Animate view height with Swift

I have view sView inside my ViewController. It height has constraint - I created IBOutlet for this constraint - sViewHeight. I want to decrease height of sView with animation.

I created function

UIView.animateWithDuration(5.5, animations: {
self.sViewHeight.constant = 50

Height of view is changing but i don't see any animation. What I am doing wrong?


use layoutIfNeeded()

 self.view.layoutIfNeeded() // force any pending operations to finish

 UIView.animateWithDuration(0.2, animations: { () -> Void in
    self.sViewHeight.constant = 50