Code is found on the Internet, but found when the direct copy can not be used, a little tidy up, for the same level of my rookie to observe the next.
(1) Introduction of "Quartzcore.framework" library, head reference.
C code
- #include <QuartzCore/CoreAnimation.h>
(2) Directly on the code, you understand.
C code
- -(Ibaction) BUTTONP: (ID) sender{
- [Self buttonanimation:sender];
- }
- -(Caanimation *) animationrotate {
- Catransform3d rotationtransform = catransform3dmakerotation (M_PI/2, 0, 1, 0);
- cabasicanimation* animation;
- Animation = [Cabasicanimation animationwithkeypath:@"transform"];
- Animation.tovalue = [Nsvalue valuewithcatransform3d:rotationtransform];
- Animation.duration = 3;
- animation.autoreverses = YES;
- Animation.cumulative = YES;
- Animation.repeatcount = 1;
- Animation.begintime = 0.1;
- Animation.delegate = self;
- return animation;
- }
- -(void) Buttonanimation: (ID) sender{
- UIButton *thebutton = sender;
- Caanimation *myanimationrotate = [self animationrotate];
- caanimationgroup* m_pgroupanimation;
- M_pgroupanimation = [Caanimationgroup animation];
- M_pgroupanimation.delegate = self;
- M_pgroupanimation.removedoncompletion = NO;
- M_pgroupanimation.duration = 10;
- M_pgroupanimation.timingfunction = [Camediatimingfunction functionwithname:kcamediatimingfunctioneaseineaseout];
- M_pgroupanimation.repeatcount = 1;
- M_pgroupanimation.fillmode = Kcafillmodeforwards;
- M_pgroupanimation.animations = [Nsarray arraywithobjects:myanimationrotate, Nil];
- [Thebutton.layer addanimation:m_pgroupanimation forkey:@"Animationrotate"];
- }
- -(void) Animationdidstop: (Caanimation *) Anim finished: (BOOL) flag{
- //todo
- }
Ps:
Catransform3dmakerotation( m_pi/2 , 0 , 1 , 0 ); The first parameter is the angle of rotation, there is a point to be famous, that is, the object back to the angle you set the shortest distance to rotate, the following three parameters are XYZ (value between -1~1) represents a vector value. Clockwise or counterclockwise rotation has not yet done what the specific parameters to control, there are friends reminded to know, thank you!