基础动画(落叶)

/*

 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

 

转载于:https://www.cnblogs.com/wukun16/p/4884167.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值