动画标签以增加和减小尺寸

use*_*428 5 swift

我一直在尝试实现一个动画,让用户注意标签中的值的变化.我想这样做,通过快速增加和减少标签的尺寸(想不出更好的方式来描述它),我做了实现这一一些进展.问题在于,动画的大小随着我想要的增加而增加; 它的大小减少的方式并不顺利.此外,一旦动画完成,字体的大小不会返回原始.

这是我有的:

func bloat() {
    UIView.beginAnimations(nil, context: nil)
    UIView.setAnimationDelegate(self)
    UIView.setAnimationDelay(0.6)
    UIView.setAnimationDuration(0.3)
    UIView.setAnimationRepeatCount(4)
    UIView.setAnimationCurve(UIViewAnimationCurve.EaseInOut)
    currentBudgetDisplay.transform = CGAffineTransformMakeScale(0.9, 0.9)
    UIView.commitAnimations()
}
Run Code Online (Sandbox Code Playgroud)

我可以做些什么改变让它按照我的意图去做?

小智 7

使用核心动画要求很简单,试试这个

func bloat() {
    var animation = CABasicAnimation(keyPath: "transform.scale")
    animation.toValue = NSNumber(float: 0.9)
    animation.duration = 0.3
    animation.repeatCount = 4.0
    animation.autoreverses = true
    currentBudgetDisplay.layer.addAnimation(animation, forKey: nil)
}
Run Code Online (Sandbox Code Playgroud)