//动画上下文
-(void)animationOfUIKit
{
    UIView *redView=[[UIView alloc]initWithFrame:CGRectMake(10, 10, 100, 100)];
    redView.backgroundColor=[UIColor redColor];
    
    [self.view addSubview:redView];
    //开始动画
    [UIView beginAnimations:@"test" context:nil];
    //动画时长
    [UIView setAnimationDuration:1];
    /*
     *要进行动画设置的地方
     */
    
    redView.backgroundColor=[UIColor blueColor];
    redView.frame=CGRectMake(50, 50, 200, 200);
    redView.alpha=0.5;
    
    
    //动画结束
    [UIView commitAnimations];
}
//通过代码块

-(void)animationOfBlock
{
    //初始化一个View,用来显示动画
    UIView *redView=[[UIView alloc]initWithFrame:CGRectMake(10, 10, 100, 100)];
    redView.backgroundColor=[UIColor redColor];
    
    [self.view addSubview:redView];
    
    [UIView animateWithDuration:1 //时长
                          delay:0 //延迟时间
                        options:UIViewAnimationOptionCurveEaseInOut//动画效果
                     animations:^{
                         
                         //动画设置区域
                         redView.backgroundColor=[UIColor blueColor];
                         redView.frame=CGRectMake(50, 50, 200, 200);
                         redView.alpha=0.5;
                         
                     } completion:^(BOOL finish){
                         //动画结束时调用
                         //............
                     }];
    
    
}

//CA动画
- (void)animationOfCABasicAnimation
{
    //创建一个CABasicAnimation对象
    CABasicAnimation *animation=[CABasicAnimation animation];
    //设置颜色
    animation.toValue=(id)[UIColor blueColor].CGColor;
    //动画时间
    animation.duration=1;
    //是否反转变为原来的属性值
    animation.autoreverses=YES;
    //把animation添加到图层的layer中,便可以播放动画了。forKey指定要应用此动画的属性
    [self.view.layer addAnimation:animation forKey:@"backgroundColor"];
}
//

//关键帧动画CAKeyframeAnimation

- (void)animationOfCAKeyframeAnimation
{
    CAKeyframeAnimation *animation=[CAKeyframeAnimation animation];
    //设置属性值
    animation.values=[NSArray arrayWithObjects:
//                      (id)self.view.backgroundColor,
                      (id)[UIColor yellowColor].CGColor,
                      (id)[UIColor greenColor].CGColor,
                      (id)[UIColor blueColor].CGColor,nil];
    animation.duration=3;
    animation.autoreverses=YES;
    //把关键帧添加到layer中
    [self.view.layer addAnimation:animation forKey:@"backgroundColor"];
}

//使用路径制作动画CAKeyframeAnimation

- (void)animationOfCAKeyframeAnimationPath
{
    //初始化一个View,用来显示动画
    UIView *redView=[[UIView alloc]initWithFrame:CGRectMake(10, 10, 20, 20)];
    redView.backgroundColor=[UIColor redColor];
    
    [self.view addSubview:redView];
    
    CAKeyframeAnimation *ani=[CAKeyframeAnimation animation];
    //初始化路径
    CGMutablePathRef aPath=CGPathCreateMutable();
    //动画起始点
    CGPathMoveToPoint(aPath, nil, 20, 20);
    CGPathAddCurveToPoint(aPath, nil,
                          160, 30,//控制点
                          220, 220,//控制点
                          240, 380);//控制点
    
    
    CGPathAddCurveToPoint(aPath, nil,
                          160, 30,//控制点
                          220, 220,//控制点
                          240, 380);//控制点
    
    ani.path=aPath;
    ani.duration=10;
    //设置为渐出
    ani.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
    //自动旋转方向
    ani.rotationMode=@"auto";
    
    [redView.layer addAnimation:ani forKey:@"position"];
}

最新文章

  1. HDU 1064 Financial Management
  2. BNUOJ 1037 精神控制
  3. Javascript验证用户输入URL地址是否正确
  4. asp.net中web.config配置节点大全详解【转】
  5. vJine 第三波 之 Lua 来袭 vJine.Lua
  6. CosCos2D-android 代码总结
  7. 32位的CPU最多只能支持最大到4GBytes的内存
  8. 利用js_API 运行对html文档元素的属性的CRUD操作
  9. WCF技术剖析之十一:异步操作在WCF中的应用(下篇)
  10. Java并发专题 带返回结果的批量任务执行 CompletionService ExecutorService.invokeAll(转)
  11. tableView等滚动视图滚动时收缩上下导航栏与标签栏
  12. Collector for ArcGIS的使用体验
  13. STAR法则的感想
  14. 如何在新浪sae服务器上面连接redis
  15. Python作业之购物车
  16. Ubuntu 16.04.4 LTS下安装JDK
  17. sticky
  18. mycat 不得不说的缘分
  19. iOS 用自签名证书实现 HTTPS 请求的原理
  20. 解决iPad/iPhone下手机号码会自动被加上a标签的问题

热门文章

  1. Python函数使用
  2. MySQL事务。
  3. JAVA 中 Map 与实体类相互转换的简单方法
  4. Centos7安装配置----1配置网络
  5. viscode 使用 格式的配置
  6. Shell命令-网络操作之基础之scp、wget
  7. Pwn-Smashes
  8. Django 模版语言
  9. javaagent的实现
  10. CF-1132 C.Painting the Fence