文档库 最新最全的文档下载
当前位置:文档库 › IOS开发之动画实现方法

IOS开发之动画实现方法

IOS开发之动画实现方法
IOS开发之动画实现方法

IOS开发中,实现动画效果主要有两种方法:在UIView层面实现或是使用CATransition进行更低层次的控制

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

1.使用UIView类函数实现:

//UIViewAnimationTransitionFlipFromLeft, 向左转动

//UIViewAnimationTransitionFlipFromRight, 向右转动

//UIViewAnimationTransitionCurlUp, 向上翻动

//UIViewAnimationTransitionCurlDown, 向下翻动

[UIView beginAnimations:@"animationID" context:nil];

[UIView setAnimationDuration:0.5f]; //动画时长

[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES]; //给视图添加过渡效果

//在这里写你的代码.

[UIView commitAnimations]; //提交动画

二、使用CATransition对象来实现:

CATransition比较强大,一般可以使用CATransition模拟UIView的动画。

/* 过渡效果

fade //交叉淡化过渡(不支持过渡方向)

push //新视图把旧视图推出去

moveIn //新视图移到旧视图上面

reveal //将旧视图移开,显示下面的新视图

cube //立方体翻滚效果

oglFlip //上下左右翻转效果

suckEffect //收缩效果,如一块布被抽走(不支持过渡方向)

rippleEffect //滴水效果(不支持过渡方向)

pageCurl //向上翻页效果

pageUnCurl //向下翻页效果

cameraIrisHollowOpen //相机镜头打开效果(不支持过渡方向)

cameraIrisHollowClose //相机镜头关上效果(不支持过渡方向)

*/

/* 过渡方向

fromRight;

fromLeft;

fromTop;

fromBottom;

*/

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;

[https://www.wendangku.net/doc/e93657269.html,yer addAnimation:animation forKey:@"animation"];

更多IOS开发基础教程,请至麦子学院官网查看>>https://www.wendangku.net/doc/e93657269.html,/course/3/。

相关文档