Animate view height with Swift
28,585
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()
})
Related videos on Youtube
Comments
-
moonvader almost 2 years
I have view sView inside my ViewController. It height has constraint - I created IBOutlet for this constraint - sViewHeightConstraint. I want to decrease height of sView with animation.
I created function
UIView.animateWithDuration(5.5, animations: { self.sViewHeightConstraint.constant = 50 })
Height of view is changing but i don't see any animation. What I am doing wrong?
-
Bhavin Bhadani almost 8 years@moonvader
layoutIfNeeded
on the view force any pending operations to finish and then in the animation block capture the frame changes. -
Bhavin Bhadani almost 8 yearsfor more info. check stackoverflow.com/questions/1182945/how-is-layoutifneeded-used