iOS_动画_实例(1)_POP_金额格式数字动画

一丶效果


iOS_动画_实例(1)_POP_金额格式数字动画_第1张图片
1.gif

二丶代码

 POPAnimatableProperty *prop = [POPAnimatableProperty propertyWithName:@"money" initializer:^(POPMutableAnimatableProperty *prop) {
    
    
    prop.writeBlock = ^(id obj, const CGFloat values[]) {
        UIButton *btn = (UIButton *)obj;
        
        @autoreleasepool {
            NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
            [formatter setNumberStyle:NSNumberFormatterNoStyle];
            [formatter setFormatWidth:9];
            [formatter setPositiveFormat:@",##0.00"];
            NSString *titleStr =  [NSString stringWithFormat:@"%.@",[formatter stringFromNumber:@(values[0])]];
            [btn setTitle:titleStr forState:UIControlStateNormal];
        }
        
    };
    //力学阀值,值越大writeBlock的调用次数越少
    prop.threshold = 1;
}];
POPBasicAnimation *anBasic = [POPBasicAnimation easeInEaseOutAnimation];
anBasic.property = prop;
anBasic.fromValue = @(0.00);
anBasic.toValue = @(100000);
anBasic.duration = 3;
[_btn pop_addAnimation:anBasic forKey:@"money"];

三丶解释:

参考文章: http://geeklu.com/2014/05/facebook-pop-usage/

Pop Animation自带的动画都是基于POPPropertyAnimation的,POPPropertyAnimation有个很重要的部分就是 POPAnimatableProperty,用来描述animatable的属性。

你可能感兴趣的:(iOS_动画_实例(1)_POP_金额格式数字动画)