ITeye博客

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

beike · 2012-08-30 23:04 · iphone/mac · 移动开发 · Markdown

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

 

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

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

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

C代码


// Hide the bar button and show the view   

self.navigationItem.rightBarButtonItem = nil;   
[self.view viewWithTag:101].alpha = 1.0f;   
 
// Bounce to 115% of the normal size   
[UIView beginAnimations:nil context:UIGraphicsGetCurrentContext()];   
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];   
[UIView setAnimationDuration:0.4f];   
[self.view viewWithTag:101].transform = CGAffineTransformMakeScale(1.15f, 1.15f);   
[UIView commitModalAnimations];   
 
// Return back to 100%   
[UIView beginAnimations:nil context:UIGraphicsGetCurrentContext()];   
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];   
[UIView setAnimationDuration:0.3f];   
[self.view viewWithTag:101].transform = CGAffineTransformMakeScale(1.0f, 1.0f);   
[UIView commitModalAnimations];   
 
// Pause for a second and appreciate the presentation   
[NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0f]];   
 
// Slowly zoom back down and hide the view   
[UIView beginAnimations:nil context:UIGraphicsGetCurrentContext()];   
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];   
[UIView setAnimationDuration:1.0f];   
[self.view viewWithTag:101].transform = CGAffineTransformMakeScale(0.01f, 0.01f);   
[UIView commitModalAnimations];   
 
// Restore the bar button   
[self.view viewWithTag:101].alpha = 0.0f;  

tnnd 原来可以这么写。

同时学到个新玩意。

C代码

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

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

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

C代码

commitModalAnimations  

具体代码实现是这样的。

Java代码


@interface UIViewDelegate : NSObject   
{   
CFRunLoopRef currentLoop;   
}   
@end   
 
@implementation UIViewDelegate   
-(id) initWithRunLoop: (CFRunLoopRef)runLoop   
{   
if (self = [super init]) currentLoop = runLoop;   
return self;   
}   
 
-(void) animationFinished: (id) sender   
{   
CFRunLoopStop(currentLoop);   
}   
@end   
 
@implementation UIView (ModalAnimationHelper)   
+ (void) commitModalAnimations   
{   
CFRunLoopRef currentLoop = CFRunLoopGetCurrent();   
 
UIViewDelegate *uivdelegate = [[UIViewDelegate alloc] initWithRunLoop:currentLoop];   
[UIView setAnimationDelegate:uivdelegate];   
[UIView setAnimationDidStopSelector:@selector(animationFinished:)];   
[UIView commitAnimations];   
CFRunLoopRun();   
[uivdelegate release];   
}   
@end 

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

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。