您的位置:首页 > 其它

iPhone的动画效果类型及实现方法

2011-03-22 16:31 567 查看
实现iPhone漂亮的动画效果主要有两种方法,

一种是UIView层面的,

一种是使用CATransition进行更低层次的控制,

第一种是UIView,UIView方式可能在低层也是使用CATransition进行了封装,它只能用于一些简单的、常用的效果展现,这里写一个常用的示例代码,供大家参考。

Cpp代码

[UIView beginAnimations:@"Curl"context:nil];//动画开始

[UIView setAnimationDuration:0.75];

[UIView setAnimationDelegate:self];

[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:myview cache:YES];

[myview removeFromSuperview];

[UIView commitAnimations];

第二种方式相对复杂一些,但如果更好的进行控制,还是使用这种方法吧,

基本使用方法可以看一下如下例子:

Cpp代码

CATransition *animation = [CATransition animation];

[animation setDuration:1.25f];

[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];

[animation setType:kCATransitionReveal];

[animation setSubtype: kCATransitionFromBottom];

[self.view.layer addAnimation:animation forKey:@"Reveal"];

这里使用了setType与setSubtype组合,这使用个比较保险,因为他的参数就是官方API里定义的,他们的参数说明可以参考如下:

[animation setType:@"suckEffect"];

这里的suckEffect就是效果名称,可以用的效果主要有:

pageCurl 向上翻一页pageUnCurl 向下翻一页

rippleEffect 滴水效果

suckEffect 收缩效果,如一块布被抽走

cube 立方体效果

oglFlip 上下翻转效果

更多的效果参考:http://iphonedevwiki.net/index.php?title=CATransition

最后再给出一种常用代码供大家参考

//创建CATransition对象

CATransition *animation = [CATransitionanimation];

//相关参数设置

[animation setDelegate:self];

[animation setDuration:1.0f];

[animation setTimingFunction:UIViewAnimationCurveEaseInOut];

//向上卷的参数

if(!isCurl)

{

//设置动画类型为pageCurl,并只卷一半

[animation setType:@"pageCurl"];

animation.endProgress=0.8;

}

//向下卷的参数

else

{

//设置动画类型为pageUnCurl,并从一半开始向下卷

[animation setType:@"pageUnCurl"];

animation.startProgress=0.2;

}

//卷的过程完成后停止,并且不从层中移除动画

[animation setFillMode:kCAFillModeForwards];

//[animation setSubtype:kCATransitionFromBottom];

[animation setSubtype:kCATransitionFromRight];

[animation setRemovedOnCompletion:NO];

isCurl=!isCurl;

[self.viewexchangeSubviewAtIndex:0withSubviewAtIndex:1];

[[self.viewlayer] addAnimation:animation forKey:@"pageCurlAnimation"];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: