button 翻转

一个按钮,点击后旋转,代码是网上找到的,不过找到的时候直接复制下来不能用,稍微整理下,为和我一样水平的菜鸟观摩一下下。

 

(1)引入“QuartzCore.framework”库,头部引用。

 

 

C代码   收藏代码
  1. #include<QuartzCore/CoreAnimation.h>  
 

(2)直接上代码,你懂的。

 

 

C代码   收藏代码
  1. -(IBAction)buttonP:(id)sender{  
  2.     [self buttonAnimation:sender];  
  3. }  
  4.   
  5. - (CAAnimation *) animationRotate {  
  6.     CATransform3D rotationTransform  = CATransform3DMakeRotation( M_PI/2 , 0 , 1 , 0 );  
  7.     CABasicAnimation* animation;  
  8.     animation = [CABasicAnimation animationWithKeyPath:@"transform"];  
  9.     animation.toValue = [NSValue valueWithCATransform3D:rotationTransform];  
  10.     animation.duration = 3;  
  11.     animation.autoreverses = YES;  
  12.     animation.cumulative = YES;  
  13.     animation.repeatCount = 1;  
  14.     animation.beginTime = 0.1;  
  15.     animation.delegate = self;  
  16.     return animation;  
  17. }  
  18.   
  19. - (void)buttonAnimation:(id) sender{  
  20.     UIButton *theButton = sender;  
  21.     CAAnimation *myAnimationRotate = [self animationRotate];  
  22.     CAAnimationGroup* m_pGroupAnimation;  
  23.     m_pGroupAnimation = [CAAnimationGroup animation];  
  24.     m_pGroupAnimation.delegate = self;  
  25.     m_pGroupAnimation.removedOnCompletion = NO;  
  26.     m_pGroupAnimation.duration = 10;  
  27.     m_pGroupAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];     
  28.     m_pGroupAnimation.repeatCount = 1;  
  29.     m_pGroupAnimation.fillMode = kCAFillModeForwards;  
  30.     m_pGroupAnimation.animations = [NSArray arrayWithObjects:myAnimationRotate, nil];  
  31.     [theButton.layer addAnimation:m_pGroupAnimation forKey:@"animationRotate"];  
  32. }  
  33.     
  34. - (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{  
  35.     //todo  
  36. }  
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值