Easy Animation with UIStackView


UIStackView leverages the power of Auto Layout by managing the layout of all the views inside. You can change property of UIStackView or its arranged subview, and place these changes inside an animation block.

For example, changing hidden property of the arranged subview.

UIView.animateWithDuration(0.3){
viewInsideStackView.hidden = true //or false
}

Here’s the animation.


iOS encourages you to create adaptive UI, when working with UIStackView, you can define size-class specific values for many of the stack view’s properties directly in Interface Builder. UIStackView automatically animates these changes for you.

For example, changing axis property of UIStackView in CompactHeight, and with some tweaks of the arranged subview’s constraints. You can have this animation without coding.


For the detail of how constraints are set up, see the full project at GitHub UIStackViewEasyAnimation


Show your support

Clapping shows how much you appreciated Nutchaphon Rewik’s story.