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
  • 7,084
  • 8
  • 45
  • 70

2 Answers2

2

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

Duncan C
  • 128,072
  • 22
  • 173
  • 272
-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
  • 18,081
  • 5
  • 50
  • 71