1 //2 //VIEWCONTROLLER.M3 //Caanimationgroup4 //5 //Created by Zhujiacong on 16/4/19.6 //copyright©2016 year WXHL. All rights reserved.7 //8 9 #import "ViewController.h"Ten One @interfaceViewcontroller () A - -@property (Weak, nonatomic) Iboutlet UIView *Animationview; the - @end - - @implementationViewcontroller + - + A- (void) Touchesbegan: (Nsset<uitouch *> *) touches withevent: (Uievent *)Event { at - //Rotate Animation -Cabasicanimation *animation1 = [cabasicanimation animationwithkeypath:@"transform.rotation.z"]; -Animation1.fromvalue = @0; -Animation1.tovalue =@ (m_pi_2); - in //Set Animation time -Animation1.duration =1; to //Repeat rotation animation +Animation1.repeatcount =huge_valf; - the * //[_animationview.layer addanimation:animation1 forkey:nil]; $ Panax Notoginseng //When you use Keyframe animations to change the background color - //1 cannot use Uicolor, must use Cgcolor the //2 cannot wrap Cgcolor as nsvalue need to use bridging to convert to ID type +Nsarray *colors = @[(__bridgeID) [Uicolor Redcolor]. Cgcolor, A(__bridgeID) [Uicolor Orangecolor]. Cgcolor, the(__bridgeID) [Uicolor Yellowcolor]. Cgcolor, +(__bridgeID) [Uicolor Greencolor]. Cgcolor, -(__bridgeID) [Uicolor Cyancolor]. Cgcolor, $(__bridgeID) [Uicolor Bluecolor]. Cgcolor, $(__bridgeID) [Uicolor Purplecolor]. Cgcolor - ]; - theCakeyframeanimation *animation2 = [cakeyframeanimation animationwithkeypath:@"BackgroundColor"]; -Animation2.values =colors;Wuyi the //Set Animation time -Animation2.duration =Ten; Wu //Repeat rotation animation -Animation2.repeatcount =huge_valf; About $ //[_animationview.layer addanimation:animation2 forkey:nil]; - - - //Create an animation group ACaanimationgroup *group =[Caanimationgroup animation]; + //add animations to the animation group theGroup.animations =@[animation1, Animation2]; - $ //set the duration of a group animation theGroup.duration =Ten; the the [_animationview.layer addanimation:group forkey:nil]; the - } in the the About- (void) Viewdidload { the [Super Viewdidload]; the the_animationview.layer.anchorpoint = Cgpointmake (0.5,2.W); + - the }Bayi the @end
Core Animation -07-Group Animation-day4