zoukankan      html  css  js  c++  java
  • Core Animation简介

    1、我们是使用Core Animatioin创建动画的时,实质上是更改CALayer的属性,然后让这些属性流畅的变化。可以使用Core Animation对象的位置、颜色、透明度以及CGAffine变换来制作动画。

    2、一个简单的小动画

    /隐式动画/

     

    - (void)viewDidLoad {

        [super viewDidLoad];

        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];

        [UIView beginAnimations:nil context:NULL];

        [UIView setAnimationDuration:2.0];  //设置动画时长

        CGAffineTransform moveTransform = CGAffineTransformMakeTranslation(200, 300);  //移动到固定的位置

        [imageView.layer setAffineTransform:moveTransform];

        imageView.layer.opacity = 1;

        

        [UIView commitAnimations];

        imageView.backgroundColor = [UIColor redColor];

        

        [self.view addSubview:imageView];

     

    }

    /显示动画/

    - (void)viewDidLoad {

        [super viewDidLoad];

        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];

        imageView.backgroundColor = [UIColor redColor];

     

        CABasicAnimation *opAnim = [CABasicAnimation animationWithKeyPath:@"opacity"];

        opAnim.duration = 3.0;

        //定义开始和结束的透明度

        opAnim.fromValue = [NSNumber numberWithFloat:1.0];

        opAnim.toValue = [NSNumber numberWithFloat:0];

        opAnim.cumulative = YES;

        opAnim.repeatCount = 6;    //重复次数

        [imageView.layer addAnimation:opAnim forKey:@"animateOpacity"];

        CGAffineTransform moveTransform = CGAffineTransformMakeTranslation(200, 300);

        CABasicAnimation *moveAnim = [CABasicAnimation animationWithKeyPath:@"transform"];

        moveAnim.duration = 6.0;

        moveAnim.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeAffineTransform(moveTransform)];

        [imageView.layer addAnimation:moveAnim forKey:@"animateTransform"];

        

        [self.view addSubview:imageView];

  • 相关阅读:
    条件随机场(crf)及tensorflow代码实例
    Adam作者大革新, 联合Hinton等人推出全新优化方法Lookahead
    33.服务之间的调用之RPC、Restful深入理解
    RPC框架调用过程详解
    Spring 面试问题 TOP 50
    myBatis+Spring+SpringMVC框架面试题整理
    JavaSSM框架精选50道面试题
    maven build的常用生命周期
    玄武短信接口和移动MAS短信接口的API封装
    Java异步执行多个HTTP请求的例子(需要apache http类库)
  • 原文地址:https://www.cnblogs.com/zhanggui/p/4242716.html
Copyright © 2011-2022 走看看