iOS開發之動畫編程的幾種方法,ios開發幾種方法

來源:互聯網
上載者:User

iOS開發之動畫編程的幾種方法,ios開發幾種方法
iOS開發之動畫編程的幾種方法

IOS中的動畫總結來說有五種:UIView<block>,CAAnimation<CABasicAnimation,CATransition,CAKeyframeAnimation>,NSTimer

這裡我就總結了一下這五種方法,其實iOS開發中動畫的編程都會在這裡面變化,所以只要弄懂了這些動畫編程就不難了。

 

一:UIView動畫一般方式
  • typedef enum {
  • UIViewAnimationTransitionNone, //普通狀態
  • UIViewAnimationTransitionFlipFromLeft, //從左往右翻轉
  • UIViewAnimationTransitionFlipFromRight, //從右往左翻轉
  • UIViewAnimationTransitionCurlUp, //向上翻頁
  • UIViewAnimationTransitionCurlDown, //向下翻頁
  • } UIViewAnimationTransition;
  • typedef enum {
  • UIViewAnimationCurveEaseInOut,
  • UIViewAnimationCurveEaseIn,
  • UIViewAnimationCurveEaseOut,
  • UIViewAnimationCurveLinear
  • } UIViewAnimationCurve;
 這裡我實現了一個自訂的動畫方法,方便使用,只需要調用就可以實現很好的功能。

 

方法的實現

-(void)UIViewAnimation:(UIView* )view frame:(CGRect)frame type:(int)type alpha:(float)alpha duration:(float)duration

{

//將對應的參數實現在方法中,調用的時候只需要輸入方法中所需要的參數就能很好的調用這個方法,並且實現想要的功能!

    [UIView beginAnimations:nil context:nil];

    [UIView setAnimationDuration:duration];

    [UIView setAnimationCurve:type];

    [UIView setAnimationDelegate:self];

    view.alpha=alpha;

    view.frame=frame;

    [UIView commitAnimations];

}

調用方法

[self UIViewAnimation:downView frame:CGRectMake(0, height, 320, 58) type:UIViewAnimationCurveEaseOut alpha:1 duration:0.3];

 

Block方式

 

 進階一點的block動畫(Next)內嵌

- (void)changeUIView{      [UIView animateWithDuration:2  delay:0   options:UIViewAnimationOptionCurveEaseOut animations:^(void){          moveView.alpha = 0.0;        }completion:^(BOOL finished){                [UIView animateWithDuration:1 delay:1.0   options:UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat    animations:^(void){                [UIView setAnimationRepeatCount:2.5];                    moveView.alpha = 1.0;                }completion:^(BOOL finished){                              }];           }];  }  

 

二:.CAAnimation

需要添加庫,和包含標頭檔

caanimation有多個子類

CABasicAnimation

 

CAKeyframeAnimation

 

CATransition
  • /*
  • kCATransitionFade;
  • kCATransitionMoveIn;
  • kCATransitionPush;
  • kCATransitionReveal;
  • */
  • /*
  • kCATransitionFromRight;
  • kCATransitionFromLeft;
  • kCATransitionFromTop;
  • kCATransitionFromBottom;
  • */
  • /*
  • cube
  • suckEffect 捲走
  • oglFlip 翻轉
  • rippleEffect 水波
  • pageCurl 翻頁
  • pageUnCurl
  • cameraIrisHollowOpen
  • cameraIrisHollowClose
  • */

 

三:NSTimer

這是一種定時器來操作動畫的方法,他可以結合上面的方法來實現動畫的多樣化!

  • }
  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.