0

Im have a nslayoutconstraint and when a user presses a button, the constraint is supposed to slowly reach zero. Currently it just automatically hits zero quickly when a button is pressed. My code isn't working. Here it is.

@IBAction func Expansion(_ sender: AnyObject) {

    UIView.animate(withDuration: 0.1, animations: {

        self.ScrolliewTopConstraint.constant = 0
        self.ScrollView.isScrollEnabled = true

    }, completion: nil)
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
user7222919
  • 149
  • 1
  • 3
  • 10

1 Answers1

3

You need to animate after setting the constant.

// set the constant
UIView.animate(withDuration: 0.1 {
   self.view.layoutIfNeeded()
}
Mundi
  • 79,884
  • 17
  • 117
  • 140