iOS button click after rollover effect

Source: Internet
Author: User

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  
    1. #include <QuartzCore/CoreAnimation.h>

(2) Directly on the code, you understand.

C code
  1. -(Ibaction) BUTTONP: (ID) sender{
  2. [Self buttonanimation:sender];
  3. }
  4. -(Caanimation *) animationrotate {
  5. Catransform3d rotationtransform = catransform3dmakerotation (M_PI/2, 0, 1, 0);
  6. cabasicanimation* animation;
  7. Animation = [Cabasicanimation animationwithkeypath:@"transform"];
  8. Animation.tovalue = [Nsvalue valuewithcatransform3d:rotationtransform];
  9. Animation.duration = 3;
  10. animation.autoreverses = YES;
  11. Animation.cumulative = YES;
  12. Animation.repeatcount = 1;
  13. Animation.begintime = 0.1;
  14. Animation.delegate = self;
  15. return animation;
  16. }
  17. -(void) Buttonanimation: (ID) sender{
  18. UIButton *thebutton = sender;
  19. Caanimation *myanimationrotate = [self animationrotate];
  20. caanimationgroup* m_pgroupanimation;
  21. M_pgroupanimation = [Caanimationgroup animation];
  22. M_pgroupanimation.delegate = self;
  23. M_pgroupanimation.removedoncompletion = NO;
  24. M_pgroupanimation.duration = 10;
  25. M_pgroupanimation.timingfunction = [Camediatimingfunction functionwithname:kcamediatimingfunctioneaseineaseout];
  26. M_pgroupanimation.repeatcount = 1;
  27. M_pgroupanimation.fillmode = Kcafillmodeforwards;
  28. M_pgroupanimation.animations = [Nsarray arraywithobjects:myanimationrotate, Nil];
  29. [Thebutton.layer addanimation:m_pgroupanimation forkey:@"Animationrotate"];
  30. }
  31. -(void) Animationdidstop: (Caanimation *) Anim finished: (BOOL) flag{
  32. //todo
  33. }

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.