自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

iPhone開發(fā)創(chuàng)建連續(xù)動畫案例

移動開發(fā) iOS
本文介紹的是iPhone開發(fā)創(chuàng)建連續(xù)動畫案例,主要介紹了iphone開發(fā)中動畫的作用,來看詳細(xì)內(nèi)容。

iPhone開發(fā)創(chuàng)建連續(xù)動畫案例是本文要介紹的內(nèi)容,主要詳細(xì)介紹了在iphone開發(fā)中連續(xù)動畫的實(shí)現(xiàn)。來看詳細(xì)內(nèi)容。在iphone開發(fā)中,我們有些時(shí)候需要創(chuàng)建連續(xù)的動畫效果,使用戶體驗(yàn)更好。

連續(xù)動畫就是一段動畫運(yùn)行完畢后調(diào)用另一段動畫,一定要保證兩段動畫沒有重疊,本文不打算使用CAKeyframeAnimation建立連續(xù)的動畫塊,雖然使用CAKeyframeAnimation更簡單(在其他的博文中實(shí)現(xiàn)此方法)

大概有兩種方法可以選擇:

1.增加延遲以便在***段動畫結(jié)束之后在啟動第二段動畫([performSelector:withObject:afterDelay:])

2.指定動畫委托回調(diào)(animationDidStop:finished:context:)

從編程的角度來說就更容易,下面我們將擴(kuò)展類UIView的方法,通過類別引入一個新的方法----commitModalAnimations.調(diào)用此方法而不是調(diào)用commitAnimations方法,它會建立一個新的runloop,該循環(huán)只有在動畫結(jié)束的時(shí)候才會停止。

這樣確保了commitModalAnimations方法只有在動畫結(jié)束才將控制權(quán)返還給調(diào)用方法,利用此擴(kuò)展方法可以將動畫塊按順序放進(jìn)代碼中,不必做任何其他的修改就能避免動畫的重疊現(xiàn)象。

代碼如下:

  1. @interface UIView (ModalAnimationHelper)  
  2. + (void) commitModalAnimations;  
  3. @end  
  4. @interface UIViewDelegate : NSObject  
  5. {  
  6. CFRunLoopRef currentLoop;  
  7. }  
  8. @end  
  9. @implementation UIViewDelegate  
  10. -(id) initWithRunLoop: (CFRunLoopRef)runLoop   
  11. {  
  12. if (self = [super init]) currentLoop = runLoop;  
  13. return self;  
  14. }  
  15. (void) animationFinished: (id) sender  
  16. {  
  17. CFRunLoopStop(currentLoop);  
  18. }  
  19. @end  
  20. @implementation UIView (ModalAnimationHelper)  
  21. + (void) commitModalAnimations  
  22. {  
  23. CFRunLoopRef currentLoop = CFRunLoopGetCurrent();  
  24. UIViewDelegate *uivdelegate = [[UIViewDelegate alloc] initWithRunLoop:currentLoop];  
  25. [UIView setAnimationDelegate:uivdelegate];  
  26. [UIView setAnimationDidStopSelector:@selector(animationFinished:)];  
  27. [UIView commitAnimations];  
  28. CFRunLoopRun();  
  29. [uivdelegate release];  
  30. }  
  31. @end 

使用:

  1. [self.view viewWithTag:101].alpha = 1.0f;  
  2. // Bounce to 115% of the normal size  
  3. [UIView beginAnimations:nil context:UIGraphicsGetCurrentContext()];  
  4. [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];  
  5. [UIView setAnimationDuration:0.4f];  
  6. [self.view viewWithTag:101].transform = CGAffineTransformMakeScale(1.15f, 1.15f);  
  7. [UIView commitModalAnimations];  
  8. // Return back to 100%  
  9. [UIView beginAnimations:nil context:UIGraphicsGetCurrentContext()];  
  10. [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];  
  11. [UIView setAnimationDuration:0.3f];  
  12. [self.view viewWithTag:101].transform = CGAffineTransformMakeScale(1.0f, 1.0f);  
  13. [UIView commitModalAnimations];  
  14. // Pause for a second and appreciate the presentation  
  15. [NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0f]];  
  16. // Slowly zoom back down and hide the view  
  17. [UIView beginAnimations:nil context:UIGraphicsGetCurrentContext()];  
  18. [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];  
  19. [UIView setAnimationDuration:1.0f];  
  20. [self.view viewWithTag:101].transform = CGAffineTransformMakeScale(0.01f, 0.01f);  
  21. [UIView commitModalAnimations]; 

小結(jié):iPhone開發(fā)創(chuàng)建連續(xù)動畫案例的內(nèi)容介紹完了,希望本文對你有所幫助!

責(zé)任編輯:zhaolei 來源: 互聯(lián)網(wǎng)
相關(guān)推薦

2011-07-25 17:13:31

iPhone 圖形 動畫

2011-08-15 13:50:06

IPhone開發(fā)UIView動畫

2011-08-12 14:04:53

iPhone動畫

2011-08-15 15:44:46

iPhone開發(fā)PDF

2011-08-18 16:24:44

iPhone開發(fā)圖片

2009-08-28 17:51:40

iPhone多視圖開發(fā)

2011-08-12 11:31:46

iPhoneUIView動畫

2011-08-16 18:13:42

IPhone開發(fā)UIView動畫

2011-07-29 14:55:25

iPhone開發(fā) 動畫過渡

2011-08-19 11:10:31

iPhone應(yīng)用

2011-08-19 10:13:05

iPhone開發(fā)

2011-08-16 15:48:37

iPhone開發(fā)抓圖程序

2011-08-09 14:54:29

iPhoneNSDateanotherDate

2011-08-15 18:02:32

iPhone開發(fā)表視圖

2011-07-08 10:15:15

IPhone 動畫

2011-08-10 14:40:23

iPhone動畫

2011-08-17 16:12:20

iPhone應(yīng)用程序

2011-08-17 16:23:31

iPhone開發(fā)UIViewContr

2011-08-18 15:24:40

iPhone國際化

2011-08-19 10:05:30

iPhone開發(fā)
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號