Skip to content

Instantly share code, notes, and snippets.

@badrinathvm
Created September 2, 2019 19:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save badrinathvm/513c0e8684136db792b848d432864f15 to your computer and use it in GitHub Desktop.
Save badrinathvm/513c0e8684136db792b848d432864f15 to your computer and use it in GitHub Desktop.
Perform animation
fileprivate func performAnimation() {
let screenSize = UIScreen.main.bounds
let stackedButtons = self.buttonStackView.arrangedSubviews
let animation = UIViewPropertyAnimator(duration: 0.3, curve: .easeOut) {
//hide or show the stackview.
self.buttonStackView.isHidden = self.buttonsAreHidden
/// change button image and update the width constraint
self.updateButtonImage = !self.buttonsAreHidden
self.widthConstant = self.buttonsAreHidden ? self.priceButton.frame.width : screenSize.size.width - 20
//handle left borders while animating.
stackedButtons.forEach({ (button) in
button.layer.sublayers?.first?.isHidden = self.buttonsAreHidden
})
//remove all existing constraints
self.backgroundView.constraints.forEach({ (constraint) in
constraint.isActive = false
})
self.view.layoutIfNeeded()
}
animation.startAnimation()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment