前言
一个简单的利用 透明度和 缩放 实现的 数字倍数动画
实现思路
上代码 看比较清晰
// 数字跳动动画
- (void)labelDanceAnimation:(NSTimeInterval)duration {
//透明度
CABasicAnimation *opacityAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
opacityAnimation.duration = 0.4 * duration;
opacityAnimation.fromValue = @0.f;
opacityAnimation.toValue = @1.f;
//缩放
CAKeyframeAnimation *scaleAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];
scaleAnimation.duration = duration;
scaleAnimation.values = @[@3.f, @1.f, @1.2f, @1.f];
scaleAnimation.keyTimes = @[@0.f, @0.16f, @0.28f, @0.4f];
scaleAnimation.removedOnCompletion = YES;
scaleAnimation.fillMode = kCAFillModeForwards;
CAAnimationGroup *animationGroup = [CAAnimationGroup animation];
animationGroup.animations = @[opacityAnimation, scaleAnimation];
animationGroup.duration = duration;
animationGroup.removedOnCompletion = YES;
animationGroup.fillMode = kCAFillModeForwards;
[self.comboLabel.layer addAnimation:animationGroup forKey:@"kComboAnimationKey"];
}
利用一个透明度从 0 ~ 1之间的alpha,然后缩放 之后加到动画组实现一下就好了
切记动画完成最好移除 否则可能引起动画内存问题
这里设置斜体字体
self.comboLabel.font = [UIFont fontWithName:@"AvenirNext-BoldItalic" size:50];
看着比较明显
最后按钮点击的时候调用
- (IBAction)clickAction:(UIButton *)sender {
self.danceCount++;
[self labelDanceAnimation:0.4];
self.comboLabel.text = [NSString stringWithFormat:@"+ %tu",self.danceCount];
}
如果实现 dozen动画的话很简单, danceCount % 10 == 0 求模就行了.
总结
这个动画比较适合 有些直播场景的点击操作计数相关.
iOS数字倍数动画Demo获取,可加iOS开发交流群:624212887,获取Demo,以及更多iOS技术资料
文章来源于网络,如有侵权请联系小编删除