iPhone开发中关于UIView Animation实现效果

移动开发 iOS
iPhone开发中关于UIView Animation实现效果是本文要介绍的内容,主要是来学习UIView Animation一连串的实现效果,具体内容我们来看本文如何实现。

iPhone开发中关于UIView Animation实现效果是本文要介绍的内容,主要是来学习UIView Animation一连串的实现效果,具体内容我们来看本文如何实现。之前受某人影响以为一连串的UIView Animation 只能这么写:

在某个animation 设置delegate ,然后在 delegate 函数中再调用另一个函数。

今天偷闲决定看 iPhone cookbook 代码查漏补缺下,结果发现这代码:

C代码

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

tnnd 原来可以这么写。

同时学到个新玩意。

C代码

  1. [NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0f]];  

PS. 原来这个例子就叫做 Modal View Animation 罪过罪过,搞了这么久iPhone还不知道这东西。

抱歉,看错了,原来是作者自己实现的方法,仔细一看原来

C代码

  1. commitModalAnimations  

具体代码实现是这样的。

Java代码

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

小结:iPhone开发中关于UIView Animation实现效果的内容介绍完了,希望通过本文的学习能对你有所帮助!

责任编辑:zhaolei 来源: 网易博客
相关推荐

2013-07-25 13:43:23

iOS开发学习UIView的Anim

2011-08-16 18:13:42

IPhone开发UIView动画

2011-08-15 13:50:06

IPhone开发UIView动画

2011-08-12 14:04:53

iPhone动画

2011-08-12 11:31:46

iPhoneUIView动画

2011-08-10 14:40:23

iPhone动画

2011-08-11 10:16:23

iPhoneUIView视图

2011-08-11 10:27:37

iPhoneUIView视图

2011-07-08 15:08:16

iPhone 图片

2011-07-08 10:15:15

IPhone 动画

2011-08-09 17:12:30

iPhoneCFRunLoop

2011-07-29 13:27:48

iPhone 开发 Nib

2011-08-22 15:15:49

iPhone开发NSMutableAr排序

2011-08-15 13:44:07

iPhone开发UITableView

2011-08-18 15:24:40

iPhone国际化

2011-08-08 14:07:49

iPhone开发 字体

2011-08-16 18:56:11

iPhone开发Three20

2011-08-15 09:58:25

iPhoneXib文件UITableView

2011-08-15 15:44:46

iPhone开发PDF

2011-08-18 16:24:44

iPhone开发图片
点赞
收藏

51CTO技术栈公众号