`
beike
  • 浏览: 356295 次
社区版块
存档分类
最新评论

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

 
阅读更多

http://mobile.51cto.com/iphone-285320.htm

 

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实现效果的内容介绍完了,希望通过本文的学习能对你有所帮助!

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics