zoukankan      html  css  js  c++  java
  • 关键帧动画(2)心脏的跳动

    //

    //  ViewController.m

    //  UI-NO-38-1基础动画实例1

    //

    //  Created by 容伟 on 15/9/17.

    //  Copyright (c) 2015年 容伟. All rights reserved.

    //

    /*

     CAKeyframeAnimation 也属于 CAPropertyAnimation

     关键帧动画  可以让我们精准的控制动画效果  它的原理是 把动画序列里面比较关键的帧取出来  设置他的动画效果

     

     values属性 执行动画轨迹的路径

     path 属性  执行动画轨迹的数组

     

     

     */

    #import "ViewController.h"

     

    @interface ViewController ()

    {

        CALayer *petalLayer;

    }

    @end

     

    @implementation ViewController

     

    - (void)viewDidLoad {

        [super viewDidLoad];

        self.view.backgroundColor = [UIColor whiteColor];

        UIImageView *imageView = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];

        NSString *path = [[NSBundle mainBundle] pathForResource:@"落叶" ofType:@"jpg"];

        imageView.image = [UIImage imageWithContentsOfFile:path];

        

        [self.view addSubview:imageView];

        

        [self addPetal];

     

     

    }

     

    - (void)addPetal {

        NSString *path = [[NSBundle mainBundle] pathForResource:@"petal" ofType:@"jpg"];

        UIImage *petal = [UIImage imageWithContentsOfFile:path];

        petalLayer = [[CALayer alloc] init];

        petalLayer.bounds = CGRectMake(0, 0, petal.size.width, petal.size.height);

        petalLayer.position = CGPointMake(150, 250);

        petalLayer.contents = (id)petal.CGImage;

        [self.view.layer addSublayer:petalLayer];

        

    }

     

    - (void)dropAnimation {

        CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];

        animation.fromValue = [NSValue valueWithCGPoint:petalLayer.position];

        animation.toValue = [NSValue valueWithCGPoint:CGPointMake(150, 600)];

        animation.duration = 5;

        animation.removedOnCompletion = NO;

        animation.fillMode = kCAFillModeBoth;

        [petalLayer addAnimation:animation forKey:@"show"];

        

        

    }

     

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

        [self dropAnimation];

    }

     

    - (void)didReceiveMemoryWarning {

        [super didReceiveMemoryWarning];

        // Dispose of any resources that can be recreated.

    }

     

    @end


  • 相关阅读:
    解释一下什么是servlet?
    HTTP请求的GET与POST方式的区别
    金额转换,阿拉伯数字的金额转换成中国传统的形式如:(¥1011)->(一千零一拾一元整)输出?
    Java中的异常处理机制的简单原理和应用。
    error和exception有什么区别?
    运行时异常与一般异常有何异同?
    jsp有哪些动作?作用分别是什么?
    jsp有哪些内置对象?作用分别是什么? 分别有什么方法?
    一个纸杯的测试用例
    白盒测试黑盒测试区别
  • 原文地址:https://www.cnblogs.com/wukun16/p/4884168.html
Copyright © 2011-2022 走看看