Pop numeric animation
Effect
Source
Https://github.com/YouXianMing/Animations
////POPNUMBERCONTROLLER.M//Animations////Created by youxianming on 15/11/18.//copyright©2015 year youxianming. All rights reserved.//#import "PopNumberController.h"#import "POPNumberAnimation.h"#import "GCD.h"#import "StringAttributeHelper.h"@interfacePopnumbercontroller () <POPNumberAnimationDelegate>@property (nonatomic, strong) Popnumberanimation*numberanimation, @property (nonatomic, strong) Gcdtimer*timer; @property (nonatomic, strong) UILabel*label;@end@implementationPopnumbercontroller- (void) viewdidload {[Super viewdidload];}- (void) Setup {[Super Setup]; _label= [[UILabel alloc] Initwithframe:cgrectmake (0,0, -, -)]; _label.textalignment=Nstextalignmentcenter; _label.center=Self.view.center; [Self.view Addsubview:_label]; //Init numberanimation.Self.numberanimation =[[Popnumberanimation alloc] init]; Self.numberanimation.Delegate=Self ; //Timer event.__weak Popnumbercontroller *weakself =Self ; Self.timer=[[Gcdtimer alloc] Initinqueue:[gcdqueue Mainqueue]]; [Self.timerEvent:^{ //Start Animation.[Weakself confignumberanimation]; [Weakself.numberanimation startanimation]; } timeintervalwithsecs:3. f]; [Self.timer start];}- (void) confignumberanimation {self.numberAnimation.fromValue=Self.numberAnimation.currentValue; Self.numberAnimation.toValue= (Arc4random ()%101/1. f); Self.numberAnimation.duration=2. F; Self.numberAnimation.timingFunction= [Camediatimingfunction functionwithcontrolpoints:0.69:0.11:0.32:0.88]; [Self.numberanimation savevalues];}- (void) Popnumberanimation: (Popnumberanimation *) numberanimation CurrentValue: (cgfloat) CurrentValue {//Init string.NSString *numberstring = [NSString stringWithFormat:@"%.1f", CurrentValue]; NSString*mpsstring =@"MPs"; NSString*totalstring = [NSString stringWithFormat:@"%@ %@", numberstring, mpsstring]; //Init string ranges.Nsrange Mpsrange =[totalstring rangeofstring:mpsstring]; Nsrange Numberrange=[totalstring rangeofstring:numberstring]; Nsrange Totalrange= Nsmakerange (0, totalstring.length); //Init attributes.Fontattribute *totalfont = [FontattributeNew]; Totalfont.font= Font_avenir_light ( -. f); Totalfont.effectrange=Totalrange; Fontattribute*numberfont = [FontattributeNew]; Numberfont.font= Font_hyqihei ( -. f); Numberfont.effectrange=Numberrange; Foregroundcolorattribute*totalcolor = [ForegroundcolorattributeNew]; Totalcolor.color=[Uicolor Blackcolor]; Totalcolor.effectrange=Totalrange; Foregroundcolorattribute*mpscolor = [ForegroundcolorattributeNew]; Mpscolor.color= [Self Mpscolorwithvalue:currentvalue/ -. f]; Mpscolor.effectrange=Mpsrange; Foregroundcolorattribute*numcolor = [ForegroundcolorattributeNew]; Numcolor.color= [Self Numcolorwithvalue:currentvalue/ -. f]; Numcolor.effectrange=Numberrange; //Create richstring.Nsmutableattributedstring *richstring =[[Nsmutableattributedstring alloc] initwithstring:totalstring]; [Richstring Addstringattribute:totalfont]; [Richstring Addstringattribute:totalcolor]; [Richstring Addstringattribute:numberfont]; [Richstring Addstringattribute:mpscolor]; [Richstring Addstringattribute:numcolor]; _label.attributedtext=richstring;}-(Uicolor *) Numcolorwithvalue: (cgfloat) value {return[Uicolor Colorwithred:value Green:0Blue0Alpha1. f];}-(Uicolor *) Mpscolorwithvalue: (cgfloat) value {return[Uicolor colorwithred:0Green:value/2. F Blue:value/3. f Alpha:value];}@end
Details
Pop numeric animation