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?
1) Control-drag from a frame view (e.g. questionFrame) to main View, in the pop-up select "Equal heights". 2)Then go to size inspector of the frame, click edit "Equal height to Superview" constraint, set the multiplier to 0.7 and hit return.
To be exact, whenever you want to animate the view, you actually call layoutIfNeeded on the superview of that view. Try this instead: UIView. animate(withDuration: 0.1, delay: 0.1, options: UIViewAnimationOptions.
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() })
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With