詳解iPhone開發中各種動畫實現效果

來源:互聯網
上載者:User

iPhone開發中各種動畫實現效果是本文要介紹的內容,iphone中存在很多好看的動畫效果,用於頁面的切換等。其中某些是apple私人的,據說私人的無法通過apple的審批。最近工作中剛好用到過其中的某些動畫,所以在網上搜了下資料,瞭解了下這些動畫。這裡就自己的理解做一下總結,如有錯誤或遺漏,盡請諒解。

1、UIView 動畫

官方API中,使用UIView可以設定5個動畫效果,分別為:

 
  1. UIViewAnimationTransitionNone    不使用動畫  
  2.  
  3. UIViewAnimationTransitionFlipFromLeft    從左向右旋轉翻頁  
  4.  
  5. UIViewAnimationTransitionFlipFromRight    從右向左旋轉翻頁,與UIViewAnimationTransitionFlipFromLeft相反  
  6.  
  7. UIViewAnimationTransitionCurlUp    捲曲翻頁,從下往上  
  8.  
  9. UIViewAnimationTransitionCurlDown    捲曲翻頁,從上往下  
  10.  
  11. 詳細請參見UIViewAnimationTransition 

例子:

 
  1. [UIView beginAnimations:@"animationID" context:nil];//開始一個動畫塊,第一個參數為動畫塊標識
  2.  
  3. [UIView setAnimationDuration:0.5f];//設定動畫的期間  
  4.  
  5. [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];  
  6.        //設定動畫塊中的動畫屬性變化的曲線,此方法必須在beginAnimations方法和commitAnimations,預設即為UIViewAnimationCurveEaseInOut效果。
  7. 詳細請參見UIViewAnimationCurve  
  8.  
  9. [UIView setAnimationRepeatAutoreverses:NO];//設定是否自動反轉當前的動畫效果  
  10.  
  11. [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
  12. //設定過渡的動畫效果,此處第一個參數可使用上面5種動畫效果  
  13.  
  14. [self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0];//頁面翻轉  
  15.  
  16. [UIView commitAnimations];//提交動畫 

2、公用動畫效果

使用CATransiton可以設定4種動畫效果,分別為:

 
  1. NSString * const kCATransitionFade;//漸漸消失  
  2.  
  3. NSString * const kCATransitionMoveIn;//覆蓋進入  
  4.  
  5. NSString * const kCATransitionPush;//推出  
  6.  
  7. NSString * const kCATransitionReveal;//與MoveIn相反 

例子:

 
  1. CATransition *animation = [CATransition animation];  
  2.  
  3. animation.duration = 0.5f;  
  4.  
  5. animation.timingFunction = UIViewAnimationCurveEaseInOut;  
  6.  
  7. animation.type = kCATransitionPush;//設定上面4種動畫效果  
  8.  
  9. animation.subtype = kCATransitionFromTop;//設定動畫的方向,有四種,
  10.  
  11. 分別為kCATransitionFromRight、kCATransitionFromLeft、kCATransitionFromTop、kCATransitionFromBottom  
  12.  
  13. [self.view.layer addAnimation:animation forKey:@"animationID"]; 

3、私人動畫

iphone種還有很多動畫是蘋果私人的,例如刪除照片的動畫等,

私人動畫可以直接在animation.type中傳入動畫的字串即可。動畫有以下幾種:

 
  1. cube:像立方體一樣翻轉  
  2.  
  3. suckEffect:漸漸縮小,與刪除照片動畫一樣  
  4.  
  5. oglFlip:上下旋轉,當subType為fromLeft或者fromRight時,
  6. 與UIViewAnimationTransitionFlipFromLeft和UIViewAnimationTransitionFlipFromRight一樣  
  7.  
  8. rippleEffect:水波效果  
  9.  
  10. pageCurl:與UIViewAnimationTransitionCurlUp一樣  
  11.  
  12. pageUnCurl:與UIViewAnimationTransitionCurlDown一樣  
  13.  
  14. cameraIrisHollowOpen:First half of cameraIris.  
  15.  
  16. cameraIrisHollowClose:Second half of cameraIris 

以上所有動畫效果的demo請見http://www.cocoachina.com/bbs/read.php?tid-11820.html,在此感謝樓主的分享,給我的學習帶來很到的協助。

UIViewAnimationState描述:http://www.iphonedevwiki.net/index.php/UIViewAnimationState

同時,本人在使用UIView實現suckEffect縮小的效果過程中遇到一個問題不知道如何定位),經過搜尋終覓得解決方案,分享如下:

 
  1. [UIView beginAnimations:@"suck" context:NULL];  
  2. [UIView setAnimationTransition:103 forView:self.view cache:YES];  
  3. [UIView setAnimationDuration:0.5f];  
  4. if (self.interfaceOrientation  == UIInterfaceOrientationPortrait || self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) 
  5. {  
  6.  [UIView setAnimationPosition:CGPointMake(44, 42)];  
  7. }else {  
  8. [UIView setAnimationPosition:CGPointMake(320 , 42)];  
  9. }  
  10. [UIView commitAnimations]; 

其中setAnimationPosition方法就是用於設定縮小點的位置的,此處雖然會報一個警告,但是結果還是正確的。

小結:詳解iPhone開發中各種動畫實現效果的內容介紹完了,希望通過本文的學習能對你有所協助!

相關文章

聯繫我們

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