iPhone動畫實現兩種表現方法

來源:互聯網
上載者:User

iPhone動畫實現兩種表現方法是本文要介紹的內容,實現iphone漂亮的動畫效果主要有兩種方法,一種是UIView層面的,一種是使用CATransition進行更低層次的控制,

第一種是UIViewUIView方式可能在低層也是使用CATransition進行了封裝,它只能用於一些簡單的、常用的效果展現,這裡寫一個常用的範例程式碼,供大家參考。

 
  1. [UIView beginAnimations:@"Curl"context:nil];//動畫開始   
  2. [UIView setAnimationDuration:0.75];   
  3. [UIView setAnimationDelegate:self];   
  4. [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:myview cache:YES];   
  5. [myview removeFromSuperview];   
  6. [UIView commitAnimations];  

第二種方式相對複雜一些,但如果更好的進行控制,還是使用這種方法吧,基本使用方法可以看一下如下例子:

 
  1. CATransition *animation = [CATransition animation];   
  2. [animation setDuration:1.25f];  
  3.  [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];   
  4.  [animation setType:kCATransitionReveal];   
  5.  [animation setSubtype: kCATransitionFromBottom];   
  6.  [self.view.layer addAnimation:animation forKey:@"Reveal"];  

這裡使用了setType與setSubtype組合,這使用個比較保險,因為他的參數就是官方API裡定義的,他們的參數說明可以參考如下:

setType:可以返回四種類型:

 
  1. kCATransitionFade淡出   
  2. kCATransitionMoveIn覆蓋原圖   
  3. kCATransitionPush推出   
  4. kCATransitionReveal底部顯出來  

setSubtype:也可以有四種類型:

 
  1. kCATransitionFromRight;  
  2.  kCATransitionFromLeft(預設值)   
  3.  kCATransitionFromTop;   
  4.  kCATransitionFromBottom 

還有一種設定動畫類型的方法,不用setSubtype,只用setType

 
  1. [animation setType:@"suckEffect"];  

這裡的suckEffect就是效果名稱,可以用的效果主要有:

pageCurl 向上翻一頁 pageUnCurl 向下翻一頁 rippleEffect 滴水效果 suckEffect 收縮效果,如一塊布被抽走 cube 立方體效果 oglFlip 上下翻轉效果
最後再給出一種常用代碼供大家參考。

 
  1. // Curl the image up or down CATransition *animation = [CATransition animation];  
  2.  [animation setDuration:0.35];   
  3. [animation setTimingFunction:UIViewAnimationCurveEaseInOut];  
  4.  if (!curled){  
  5.   //animation.type = @"mapCurl";  
  6.   animation.type = @"pageCurl";   
  7.   animation.fillMode = kCAFillModeForwards;  
  8.    animation.endProgress = 0.99;   
  9. } else {  
  10.   //animation.type = @"mapUnCurl";   
  11. animation.type = @"pageUnCurl";   
  12. animation.fillMode = kCAFillModeBackwards;   
  13. animation.startProgress = 0.01;  
  14.  }   
  15.  [animation setRemovedOnCompletion:NO];   
  16.  [view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];  
  17.   [view addAnimation:animation forKey"pageCurlAnimation"];  
  18.    // Disable user interaction where necessary if (!curled) {   }   
  19. else {   
  20.   }  
  21.    curled = !curled;  

小結:iPhone動畫實現兩種表現UIViewCATransition方法的內容介紹完了,希望通過本文的學習對你有所協助!

聯繫我們

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