Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

UIStackView – Hide/Unhide animation not as expected

I am trying to perform smooth animation when hiding and unhiding UI elements in a vertical StackView. When the UI element has height constraint set, I am unable to obtain expected result. The view does not hide rapidly alongside the animating stackView.

Below is the button action

@IBAction
func didSelect(_ sender: UIButton) {
    UIView.animate(withDuration: 3) {
        self.viewToHide.isHidden.toggle()
    }
}

and Storyboard

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

enter image description here

The green view is expected to update animate along with the animating stackView. But, it hides after completing the animation and unhides instantly as animation starts when toggled. What am I missing here?

>Solution :

You need to reduce viewToHigh constraint priority to make it work. For example:

enter image description here

Output:

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading