读书人

[zt]iPhone开发中关于UIView Animatio

发布时间: 2012-09-28 00:03:35 作者: rapoo

[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? ?self.navigationItem.rightBarButtonItem?=?nil;? ?
  2. [self.view?viewWithTag:101].alpha?=?1.0f;? ??
  3. //?Bounce?to?115%?of?the?normal?size? ?[UIView?beginAnimations:nil?context:UIGraphicsGetCurrentContext()];? ?
  4. [UIView?setAnimationCurve:UIViewAnimationCurveEaseInOut];? ?[UIView?setAnimationDuration:0.4f];? ?
  5. [self.view?viewWithTag:101].transform?=?CGAffineTransformMakeScale(1.15f,?1.15f);? ?[UIView?commitModalAnimations];? ?
  6. ?//?Return?back?to?100%? ?
  7. [UIView?beginAnimations:nil?context:UIGraphicsGetCurrentContext()];? ?[UIView?setAnimationCurve:UIViewAnimationCurveEaseInOut];? ?
  8. [UIView?setAnimationDuration:0.3f];? ?[self.view?viewWithTag:101].transform?=?CGAffineTransformMakeScale(1.0f,?1.0f);? ?
  9. [UIView?commitModalAnimations];? ??
  10. //?Pause?for?a?second?and?appreciate?the?presentation? ?[NSThread?sleepUntilDate:[NSDate?dateWithTimeIntervalSinceNow:1.0f]];? ?
  11. ?//?Slowly?zoom?back?down?and?hide?the?view? ?
  12. [UIView?beginAnimations:nil?context:UIGraphicsGetCurrentContext()];? ?[UIView?setAnimationCurve:UIViewAnimationCurveEaseInOut];? ?
  13. [UIView?setAnimationDuration:1.0f];? ?[self.view?viewWithTag:101].transform?=?CGAffineTransformMakeScale(0.01f,?0.01f);? ?
  14. [UIView?commitModalAnimations];? ??
  15. //?Restore?the?bar?button? ?[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. CFRunLoopRef?currentLoop;? ?}? ?
  3. @end? ??
  4. @implementation?UIViewDelegate? ?-(id)?initWithRunLoop:?(CFRunLoopRef)runLoop? ?
  5. {? ?if?(self?=?[super?init])?currentLoop?=?runLoop;? ?
  6. return?self;? ?}? ?
  7. ?-(void)?animationFinished:?(id)?sender? ?
  8. {? ?CFRunLoopStop(currentLoop);? ?
  9. }? ?@end? ?
  10. ?@implementation?UIView?(ModalAnimationHelper)? ?
  11. +?(void)?commitModalAnimations? ?{? ?
  12. CFRunLoopRef?currentLoop?=?CFRunLoopGetCurrent();? ??
  13. UIViewDelegate?*uivdelegate?=?[[UIViewDelegate?alloc]?initWithRunLoop:currentLoop];? ?[UIView?setAnimationDelegate:uivdelegate];? ?
  14. [UIView?setAnimationDidStopSelector:@selector(animationFinished:)];? ?[UIView?commitAnimations];? ?
  15. CFRunLoopRun();? ?[uivdelegate?release];? ?
  16. }? ?@end?

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

读书人网 >Iphone

热点推荐