ios按鈕點擊後翻轉效果

來源:互聯網
上載者:User

代碼是網上找到的,不過找到的時候直接複製下來不能用,稍微整理下,為和我一樣水平的菜鳥觀摩一下下。

 

(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. }  

 

PS:

 

CATransform3DMakeRotation( M_PI/2 , 0 , 1 , 0 );第一個參數是旋轉的角度,有一點需要著名,就是對象回按照你設定的角度的最短距離去旋轉,後面三個參數分別是xyz(-1~1之間的值)代表的一個向量值。順時針或者逆時針旋轉尚未搞定具體是什麼參數來控制的,有知道的朋友提醒下,謝謝!

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.