巴扎黑2017-04-17 13:53:25
Because it’s just a performance animation, it doesn’t really modify anything, and it’s different from those UIView.animateXXX
things. If you want to retain the effect, you need to set it yourself outside of addAnimation
, like this:
rectLayer.addAnimation(alphaAnim, forKey: "alphaAnim")
rectLayer.opacity = 1
Originally rectLayer.opacity
is 0
, and the function of alphaAnim
is to fade it into 1
, so that after setting, it will remain as 1
after the animation ends.
Sometimes it’s really not easy to do this, but there are alternatives:
alphaAnim.removedOnCompletion = false
alphaAnim.fillMode = kCAFillModeForwards
Let the animation not be removed after it is completed, and stay in the state where the animation ends. But remember that the original settings of the animated elements have not changed in any way due to animation, otherwise it will be all kinds of mess. . .