1 #import "NJViewController.h"2 3 @interfaceNjviewcontroller ()4 5@property (Weak, nonatomic) Iboutlet UIView *CustomView;6-(Ibaction) Btnclick: (ID) sender;7 @end8 9 @implementationNjviewcontrollerTen One- (void) Touchesbegan: (Nsset *) touches withevent: (Uievent *)Event A { - - [self test1]; the //[self test1]; - } - -- (void) Test1 + { - //1. Create a core animation +Cakeyframeanimation *keyanima =[cakeyframeanimation animation]; A //1.1 Tell the system what animations to perform atKeyanima.keypath =@"position"; - -Cgmutablepathref Path =cgpathcreatemutable (); -Cgpathaddellipseinrect (Path, NULL, CGRectMake (0, -, $, $)); - -Keyanima.path =path; in cgpathrelease (path); - to //1.2 Save status after execution + //1.2.1 Do not delete animations after execution finishes -Keyanima.removedoncompletion =NO; the //Save up-to-date status after 1.2.2 execution *Keyanima.fillmode =kcafillmodeforwards; $ Panax Notoginseng //1.3 Setting Animation time -Keyanima.duration =2; the //2. Watch when the animation starts and when it's done +Keyanima.Delegate=Self ; A //3. Add a core animation the[Self.customView.layer Addanimation:keyanima Forkey:@"ABC"]; + } - $-(Ibaction) Btnclick: (ID) Sender { $ - //Stop Animation -[Self.customView.layer Removeanimationforkey:@"ABC"]; the } - Wuyi the- (void) Test - { Wu //1. Create a core animation -Cakeyframeanimation *keyanima =[cakeyframeanimation animation]; About //1.1 Tell the system what animations to perform $Keyanima.keypath =@"position"; - //nsvalue *v1 = [Nsvalue valuewithcgpoint:cgpointmake (0)]; -Nsvalue *v2 = [Nsvalue valuewithcgpoint:cgpointmake ( -, -)]; -Nsvalue *v3 = [Nsvalue valuewithcgpoint:cgpointmake ( -, $)]; ANsvalue *v4 = [Nsvalue valuewithcgpoint:cgpointmake (0, $)]; +Nsvalue *v5 = [Nsvalue valuewithcgpoint:cgpointmake (0, -)]; the -Keyanima.values =@[v2, v3, V4, V5]; $ the //keyanima.keytimes = @[@ (0.5), @ (0.5), @ (0.5)]; the theKeyanima.timingfunction =[Camediatimingfunction functionwithname:kcamediatimingfunctioneaseineaseout]; the - //1.2 Save status after execution in //1.2.1 Do not delete animations after execution finishes theKeyanima.removedoncompletion =NO; the //Save up-to-date status after 1.2.2 execution AboutKeyanima.fillmode =kcafillmodeforwards; the the //1.3 Setting Animation time theKeyanima.duration =2; + - //2. Watch when the animation starts and when it's done theKeyanima.Delegate=Self ;Bayi the the //2. Add a core animation - [Self.customView.layer Addanimation:keyanima forkey:nil]; - } the the- (void) Animationdidstart: (Caanimation *) Anim the { theNSLog (@"Animationdidstart"); - } the the- (void) Animationdidstop: (Caanimation *) Anim finished: (BOOL) Flag the {94NSLog (@"Animationdidstop"); the } the the 98 @end
Key-Frame animations for iOS core animations