内容简介:一个简单的利用 透明度和 缩放 实现的 数字倍数动画上代码 看比较清晰
前言
一个简单的利用 透明度和 缩放 实现的 数字倍数动画
实现思路
上代码 看比较清晰
// 数字跳动动画
- (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技术资料
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- 数字中台:企业数字营销的支点
- 对称加密,非对称加密,数字签名,数字证书,SSL握手
- 海康联手新中大推进「数字建企」,实现数字化工地与项目管理
- 数字政务势在必行 人民政务扛起国家队大旗推动数字政务发展
- Oracle字符类型存数字及查询数字时使用单引号走不走索引的问题
- Python Number(数字)
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Making Things See
Greg Borenstein / Make / 2012-2-3 / USD 39.99
Welcome to the Vision Revolution. With Microsoft's Kinect leading the way, you can now use 3D computer vision technology to build digital 3D models of people and objects that you can manipulate with g......一起来看看 《Making Things See》 这本书的介绍吧!