I have an animation which basically increases and decreases a button's scale to draw the user's attention to the fact that it is tappable.
It works fine, but it isn't very smooth. Once it reaches it's full size, it just switches immediately to reducing in size. I was wondering how I could add a deceleration period and an acceleration period to it so that each time it changes direction, it slows down first and then speeds up?
This is my code:
func bloat() {
var animation = CABasicAnimation(keyPath: "transform.scale")
animation.toValue = NSNumber(float: 0.9)
animation.duration = 1
animation.repeatCount = 100
animation.autoreverses = true
faceButton.layer.addAnimation(animation, forKey: nil)
}
You need to add a timing function. In order to keep things simple, you should use one of the predefined ones.
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut);
This timing function will add acceleration to the start and deceleration to the end.