I have seen here very smooth animation of hiding/showing subview in UIStackView
.
I try to reproduce it in my own application but I have meet a problem.
View that is hidden during animation proces does not resize. It just wait until animation finish and then disappear. Opposite to clear button
from above linked example.
My code:
UIView.animate(withDuration: 0.5,
delay: 0.0,
usingSpringWithDamping: 0.9,
initialSpringVelocity: 1,
options: [],
animations: {
self.acceptDeclineBar.isHidden = !newState
self.view.layoutIfNeeded()
},
completion: nil)
Question
Is UIStackView
give resizing animation on hide/show for free or do I need implement it for myself using height constraint for example?
Your view (self.acceptDeclineBar)
will hide when the animation completes. try to hide before the animation.
self.acceptDeclineBar.isHidden = !newState
UIView.animate(withDuration: 0.3){ [weak self]
self?.view.layoutIfNeeded()
}
or instead of hiding you can use Height Constraint
acceptDeclineBarHeightConstraint.constant = newState ? 60 (whatever Visbale size) : 0 (Hide)
UIView.animate(withDuration: 0.3){ [weak self]
self?.view.layoutIfNeeded()
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.