iOS 動畫

核心動畫  CoreAnimation 核心動畫  簡稱CA


 之前學的UIView動畫其實質上也是CoreAnimation,只是對它裏面的動畫進行了封裝

 


相關方法:

       

 + (void)setAnimationDelegate:(id)delegate;

 + (void)setAnimationWillStartSelector:(SEL)selector   當動畫即將開始時,執行delegate對象的selector,並且把beginAnimations:context:中傳入的參數傳進selector

 + (void)setAnimationDidStopSelector:(SEL)selector  當動畫結束時,執行delegate對象的selector,並且把beginAnimations:context:中傳入的參數傳進selector

 

 + (void)setAnimationDuration:(NSTimeInterval)duration   動畫的持續時間,秒爲單位

 

 + (void)setAnimationDelay:(NSTimeInterval)delay  動畫延遲delay秒後再開始

 

 + (void)setAnimationStartDate:(NSDate *)startDate   動畫的開始時間,默認爲now

 

 + (void)setAnimationCurve:(UIViewAnimationCurve)curve  動畫的節奏控制

 

 + (void)setAnimationRepeatCount:(float)repeatCount  動畫的重複次數

 

 + (void)setAnimationRepeatAutoreverses:(BOOL)repeatAutoreverses  如果設置爲YES,代表動畫每次重複執行的效果會跟上一次相反

 

 + (void)setAnimationTransition:(UIViewAnimationTransition)transition forView:(UIView *)view cache:(BOOL)cache  設置視圖view的過渡效果, transition指定過渡類型, cache設置YES代表使用視圖緩存,性能較好




動畫一:

{

開始動畫:

  [UIView beginAnimations:@“id” context:nil];  id是動畫的標示符,不能重複  

     

 …………….具體的 動畫效果 (修改alpha  bounds center  之類的屬性)   


 需要實現的效果寫完了之後,就提交動畫

 [UIView commitAnimations];

}




動畫二:

{

  [UIView beginAnimations:@“id1” context:nil]; 

 *************具體動畫的內容********

 [UIView setAnimationDuration:5];

  

 設置動畫的過渡動畫

  [UIView setAnimationTransition:過渡的動畫 forView:需要執行動畫的視圖 cache:YES];]   

  

 /*過渡的動畫效果

 typedef NS_ENUM(NSInteger, UIViewAnimationTransition) {

 UIViewAnimationTransitionNone,

 UIViewAnimationTransitionFlipFromLeft, 從左面翻轉

 UIViewAnimationTransitionFlipFromRight,從右面翻轉

 UIViewAnimationTransitionCurlUp, 向上翻頁

 UIViewAnimationTransitionCurlDown,向下翻頁

 };

 */



過渡動畫的狀態

       [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];

//    設置動畫效果過渡的狀態

    /*

     typedef NS_ENUM(NSInteger, UIViewAnimationCurve) {

     UIViewAnimationCurveEaseInOut,         // slow at beginning and end  慢進慢出

     UIViewAnimationCurveEaseIn,            // slow at beginning  快進

     UIViewAnimationCurveEaseOut,           // slow at end  快出

     UIViewAnimationCurveLinear   勻速

     };

     */


如果我們要檢測動畫執行結束,就需要掛上代理

   [UIView setAnimationDelegate:self];

//   檢測 動畫結束

   [UIView setAnimationDidStopSelector:@selector(finishAnimation)];


     [UIView commitAnimations];//  提交動畫


}

//動畫結束  執行另外一個動畫或者做其他的事情

-(void)finishAnimation

{

   上一個動畫結束後,執行的動作

}




動畫三:

-(void)viewAnimation3

{

  改變視圖的transform  屬性

   注意: transform 如果沒有還原transform   它會保持改變後的模樣

 

   視圖.transform = CGAffineTransformScale(imageView.transform,0.5, 0.5);

    //補充:

//    imageView.transform=CGAffineTransformScale(imageView.transform, 0.5, 0.5); // 實現的是放大和縮小imageView.transform=CGAffineTransformRotate(imageView.transform, M_PI_4); //實現的是旋轉 imageView.transform=CGAffineTransformTranslate(imageView.transform, 20, 0); //實現的是平移


  當動畫結束,還原圖片

    

    [UIView setAnimationDelegate:self];

    

    [UIView setAnimationDidStopSelector:@selector(recover)];


   記得按照之前的步驟寫開始動畫和提交的動畫


 }

-(void)recover

{

   視圖.transform = CGAffineTransformIdentify;



}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章