iOS中的动画右两大类1.UIView的视图动画2.Layer的动画 UIView的动画也是基于Layer的动画
动画的代码格式都很固定

1.UIView动画

一般方式
[UIView beginAnimations:@"ddd" context:nil];//设置动画
[UIView commitAnimations]; //提交动画
这两个是必须有的,然后在两句的中间添加动画的代码

[UIView beginAnimations:@"ddd" context:nil];//设置动画 ddd为动画名称
[UIView setAnimationDuration:3];//定义动画持续时间
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; //setAnimationCurve来定义动画加速或减速方式
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.window cache:YES];
//设置动画的样式  forView为哪个view实现这个动画效果
[UIView setAnimationDelay:3]; //设置动画延迟多久执行
[UIView setAnimationDelegate:self];  //设置动画的代理 实现动画执行前后的方法 在commitAnimation之前设置
[UIView setAnimationDidStopSelector:@selector(stop)];//设置动画结束后执行的方法
[UIView setAnimationWillStartSelector:@selector(star)];//设置动画将要开始执行的方法
[UIView commitAnimations]; //提交动画
typedef enum {
        UIViewAnimationTransitionNone,  //普通状态
        UIViewAnimationTransitionFlipFromLeft,  //从左往右翻转
        UIViewAnimationTransitionFlipFromRight,  //从右往左翻转
        UIViewAnimationTransitionCurlUp, //向上翻页
        UIViewAnimationTransitionCurlDown, //向下翻页
    } UIViewAnimationTransition;
typedef enum {
        UIViewAnimationCurveEaseInOut,        
        UIViewAnimationCurveEaseIn,           
        UIViewAnimationCurveEaseOut,          
        UIViewAnimationCurveLinear
    } UIViewAnimationCurve;

[UIView beginAnimations:@"ddd" context:nil]; //设置动画
view.frame = CGRectMake(200, 200, 100, 100);
[UIView commitAnimations]; //提交动画
当view从本来的frame移动到新的frame时会慢慢渐变 而不是一下就完成了 中间也可以添加到上面那段中间 只是多种效果重叠

以下这些也可以加到  [UIView beginAnimations:@"ddd" context:nil]; [UIView commitAnimations];之间

view.transform = CGAffineTransformMakeTranslation(10, 10);//设置偏移量 相对于最初的 只能偏移一次
view.transform = CGAffineTransformTranslate(view.transform, 10, 10); //设置偏移量 偏移多次

self.view.transform = CGAffineTransformMakeRotation(M_PI);//设置旋转度 只能旋转一次
self.view.transform = CGAffineTransformRotate(self.view.transform, M_PI); //旋转多次

self.view.transform = CGAffineTransformMakeScale(1.1, 1.1); //设置大小 只能改变一次 数值时相对于本来的几倍
self.view.transform = CGAffineTransformScale(self.view.transform, 1.1, 1.1);//改变多次

self.view.transform = CGAffineTransformIdentity;//回到当初的样子 执行一次
self.view.transform = CGAffineTransformInvert(self.view.transform);//得到相反的样子 大小 方向 位置执行多次

Block方式
[UIView animateWithDuration:3 animations:^(void){
           
      //这里相当于在begin和commint之间
    }completion:^(BOOL finished){
         //这里相当于动画执行完成后要执行的方法,可以继续嵌套block
    }];

2.CAAnimation
需要添加库,和包含头文件

caanimation有多个子类

CABasicAnimation

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"opacity"];
//@""里的字符串有多种,可以自己找相关资料,一定要填对,动画才会执行 opacity设置透明度 bounds.size设置大小
[animation setFromValue:[NSNumber numberWithFloat:1.0]]; //设置透明度从几开始
[animation setToValue:[NSNumber numberWithFloat:0.3]];//设置透明度到几结束
[animation setDuration:0.1]; //设置动画时间
[animation setRepeatCount:100000];//设置重复时间
[animation setRepeatDuration:4];  //会限制重复次数
[animation setAutoreverses:NO];//设置是否从1.0到0.3 再从0.3到1.0 为一次  如果设置为NO则 1.0到0.3为一次
[animation setRemovedOnCompletion:YES]; //完成时移出动画 默认也是
[view.layer addAnimation:animation forKey:@"abc"];//执行动画

CAKeyframeAnimation

CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];//设置view从初始位置经过一系列点
NSArray *postionAraay = [NSArray arrayWithObjects:[NSValue valueWithCGPoint:CGPointMake(100, 20)], [NSValue valueWithCGPoint:CGPointMake(40, 80)],[NSValue valueWithCGPoint:CGPointMake(30, 60)],[NSValue valueWithCGPoint:CGPointMake(20, 40)],[NSValue valueWithCGPoint:CGPointMake(0, 100)],nil];//设置点
   
NSArray *times = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.3],[NSNumber numberWithFloat:0.5],[NSNumber numberWithFloat:0.6],[NSNumber numberWithFloat:0.1],[NSNumber numberWithFloat:1.0], nil];  //设置移动过程的时间

[animation setKeyTimes:times];
[animation setValues:postionAraay];
[animation setDuration:5]; //设置动画时间
[bigImage.layer addAnimation:animation forKey:@"dd"]; //执行动画

CATransition

CATransition *animation = [CATransition animation];
animation.duration = 0.5f;
animation.timingFunction = UIViewAnimationCurveEaseInOut;
animation.fillMode = kCAFillModeForwards;
    /*
     kCATransitionFade;
     kCATransitionMoveIn;
     kCATransitionPush;
     kCATransitionReveal;
     */
    /*
     kCATransitionFromRight;
     kCATransitionFromLeft;
     kCATransitionFromTop;
     kCATransitionFromBottom;
     */
animation.type = kCATransitionPush;
animation.subtype = kCATransitionFromBottom;
[view.layer addAnimation:animation forKey:animation];
type也可以直接用字符串
/*
     cube
     suckEffect 卷走
     oglFlip    翻转
     rippleEffect  水波
     pageCurl   翻页
     pageUnCurl
     cameraIrisHollowOpen
     cameraIrisHollowClose
*/

最新文章

  1. Java线程池解析
  2. (原创)JAVA多线程三锁
  3. 挂载windows共享文件夹
  4. JS的prototype和__proto__ Constructor
  5. Mycat+Mysql 插入数据报错 i[Err] 1064 - partition table, insert must provide ColumnList
  6. FPGA相关术语(一)
  7. xcode 和 android studio中在Mac系统下的自动对齐快捷键
  8. 二、java中的基本数据类型
  9. uLua学习笔记(三):Unity3D和Lua之间的相互调用
  10. c++给数组赋值
  11. poj2777--Count Color(线段树,二进制转化)
  12. java多线程系列(六)---线程池原理及其使用
  13. Nagios安装、配置、问题记录
  14. VS.NET C# 开发ArcGis插件无法进入断点调试的解决方法
  15. pycharm 安装
  16. c#查找窗口的两种办法
  17. QFileSystemModel中通过flags函数反应代码的层级思考
  18. anglar cli的 rxjs_1.of is not a function
  19. 有了这套flexible.js 移动端自适应方案,你就能在移动端的来去自如, (*^__^*)
  20. centos安装tomcat7

热门文章

  1. 最新版Intel HD4000 桌面右键菜单去除方法
  2. 绑定本地Service并与之通信-----之一
  3. js基础之BOM
  4. POJ 1422 二分图(最小路径覆盖)
  5. MonoRail MVC应用(2)-构建多层结构的应用程序
  6. [转] C中的位域
  7. Controller方法的返回值
  8. linux 用户、组,修改文件权限
  9. javascript预解析和作用域
  10. AlarmManager