在新的项目中UI妹子设计出了一个相似于支付宝金额不断增长的动画,以下图: html
而后就找度娘学习下了相关经验,受到这篇博客的启发:ios核心动画高级技巧,使用CADisplayLink定时器来作此动效的引擎(其实使用NSTimer和GCD定时器也能够作到,但使用CADisplayLink最佳)。ios
....
[label pp_fromNumber:0 toNumber:100 duration:1.5 animationType:PPCounterAnimationTypeEaseOut formatBlock:^NSString *(CGFloat number) {
// 此处自由拼接内容
return [NSString stringWithFormat:@"%.2f",number];
} completeBlock:^{
// 完成的回调
}];复制代码
....
[label pp_fromNumber:0 toNumber:100 duration:1.5 animationType:PPCounterAnimationTypeEaseOut attributedFormatBlock:^NSAttributedString *(CGFloat number) {
// 此处自由设置富文本属性的内容
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@""];
return attributedString;
} completeBlock:^{
// 完成的回调
}];复制代码
....
[button pp_fromNumber:0 toNumber:100 duration:1.5 animationType:PPCounterAnimationTypeEaseOut formatBlock:^NSString *(CGFloat number) {
// 此处自由拼接内容
return [NSString stringWithFormat:@"%.2f",number];
} completeBlock:^{
// 完成的回调
}];复制代码
....
[button pp_fromNumber:0 toNumber:100 duration:1.5 animationType:PPCounterAnimationTypeEaseOut attributedFormatBlock:^NSAttributedString *(CGFloat number) {
// 此处自由设置富文本属性的内容
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@""];
return attributedString;
} completeBlock:^{
// 完成的回调
}];复制代码
[[PPCounterEngine counterEngine] fromNumber:0
toNumber:999
duration:2.f
animationOptions:PPCounterAnimationOptionCurveEaseOut
currentNumber:^(CGFloat number) {
// lable控件
self.numberLabel.stringValue = [NSString stringWithFormat:@"%ld",(NSInteger)number];
} completion:^{
// 计数完成的回调
self.numberLabel.textColor = [NSColor redColor];
}];复制代码
以上就是PPCounter的简单使用方法,更详细的用法请看Demo : github.com/jkpang/PPCo…, 欢迎Star,欢迎Fork!git