I'm trying to make an animation but I can't figure out what I'm doing wrong. I want the animation to be so that the menu enlarges just rolling down but it keeps clipping because of the constraint it will have after it is done enlarging.
I tried everything to my knowledge to try and change the order or just to keep the top anchored but until now I've been unsuccessful.
( See Imgur link for a gif with what I mean exactly, the sudden jump in position )
menuHeightConstraint is the constraint for the UIView height
code of the IBAction function
@IBAction func openMenu() {
menuIsOpen.toggle()
menuHeightConstraint.constant = menuIsOpen ? 180 : 55
logoHorizontalConstraint.constant = menuIsOpen ? 0 : -122
logoVerticalConstraint.constant = menuIsOpen ? 15 : 7
logoHeight.constant = menuIsOpen ? 75 : 40
logoWidth.constant = menuIsOpen ? 75 : 40
loginVertConstraint.constant = menuIsOpen ? 100 : 15 // label constraint
let indicator = menuIsOpen ? UIImage(systemName: "arrow.up.circle.fill") : UIImage(systemName: "arrow.down.circle.fill")
dropDownButtonImage.setImage(indicator, for: .normal)
UIView.animate(
withDuration: 0.5,
delay: 0,
options: .curveEaseIn,
animations: {
self.menuView.layoutIfNeeded()
},
completion: nil)
}
Link to GIF -----,
constraint in storyboard
CodePudding user response:
In your animations
block, change:
self.menuView.layoutIfNeeded()
to:
self.view.layoutIfNeeded()