您的位置:首页 > 其它

iPhone动画效果

2012-09-06 22:00 423 查看
实现iphone漂亮的动画效果主要有两种方法, 一种是UIView层面的, 一种是使用CATransition进行更低层次的控制。
第一种是UIView,UIView方式可能在低层也是使用CATransition进行了封装,它只能用于一些简单的、常用的效果展现。
第二种方式相对复杂一些,但是如果控制得好,建议使用CATransition,它是Core Animation Transition。

1.使用UIView类函数实现:

[UIView beginAnimations:@"animationID" context:nil];//beginAnimations是动画名,可以为nil。content是动画上下文,一般也可以写为nil。
[UIView setAnimationDuration:0.5f]; //动画时长
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; //动画缓慢曲线点
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES]; //给视图添加过渡效果
//在这里写你的代码.
[UIView commitAnimations]; //提交动画


typedef enum {
UIViewAnimationTransitionNone,
UIViewAnimationTransitionFlipFromLeft,
UIViewAnimationTransitionFlipFromRight,
UIViewAnimationTransitionCurlUp,
UIViewAnimationTransitionCurlDown,
} UIViewAnimationTransition;


2.使用CATransition对象来实现:

CATransition *animation = [CATransition animation];
animation.delegate = self;
animation.duration = 0.5f; //动画时长
animation.timingFunction = UIViewAnimationCurveEaseInOut;
animation.fillMode = kCAFillModeForwards;
animation.type = @"cube"; //过度效果
animation.subtype = @"formLeft"; //过渡方向
animation.startProgress = 0.0 //动画开始起点(在整体动画的百分比)
animation.endProgress = 1.0;  //动画停止终点(在整体动画的百分比)
animation.removedOnCompletion = NO;
[self.view.layer addAnimation:animation forKey:@"animation"];

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

setType:可以返回四种类型:

kCATransitionFade淡出

kCATransitionMoveIn覆盖原图

kCATransitionPush推出

kCATransitionReveal底部显出来

setSubtype:也可以有四种类型:

kCATransitionFromRight;

kCATransitionFromLeft(默认值)

kCATransitionFromTop;

kCATransitionFromBottom

还有种设置动画方法不用setType 与setSubtype组合,只用setType
[animation setType:@"suckEffect"];
pageCurl 向上翻一页
pageUnCurl 向下翻一页
rippleEffect 滴水效果
suckEffect 收缩效果,如一块布被抽走
cube 立方体效果
oglFlip 上下翻转效果
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  iPhone 动画效果