0

This is my code, and the skip button animation does not work. It just disappear immediately. It just disappear

skipButtonBottomConstraint.constant = -40

 UIView.animate(withDuration: 1.0, animations: {

                self.titleLabel.alpha = 0
                self.skipButton.alpha = 0
                self.pageControl.alpha = 0


                self.view.setNeedsLayout()
    })

could you explain me the reason?

Andrea Miotto
  • 5,998
  • 5
  • 40
  • 64

2 Answers2

2

I think Paul is right, and you should be calling layoutIfNeeded() inside the animation block, not setNeedsLayout()

Duncan C
  • 122,346
  • 22
  • 162
  • 258
-2

Make sure you are calling layoutIfNeeded after you setNeedsLayout

Also as Apple recommends - call it once before the animation block to ensure that all pending layout operations have been completed.

self.view.layoutIfNeeded()
self.skipButtonBottomConstraint.constant = -40
UIView.animate(withDuration: 1.0, animations: {    
        self.titleLabel.alpha = 0
        self.skipButton.alpha = 0
        self.pageControl.alpha = 0
        self.view.layoutIfNeeded()
})
Grzegorz Krukowski
  • 15,591
  • 5
  • 44
  • 63