树叶飘落

#import "ViewController.h"

#define View_Width self.view.frame.size.width

#define View_Height self.view.frame.size.height

@interface ViewController ()

{

    CALayer *_layer;

}

@end


@implementation ViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

    //self.view.backgroundColor=[UIColor greenColor];

    _layer=[CALayer layer];

    _layer.bounds=CGRectMake(0, 0, 60,60);

    _layer.cornerRadius=30;

    _layer.masksToBounds=YES;

    //_layer.position=CGPointMake(View_Width-20, (View_Height-20*2)/2+20);

    _layer.position=CGPointMake(View_Width/2, 20);

    //_layer.backgroundColor=[UIColor orangeColor].CGColor;

    _layer.contents=(id)[UIImage imageNamed:@"tree.png"].CGImage;

    [self.view.layer addSublayer:_layer];


}

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

{

    //1.创建一个关键帧动画

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

    

    //2.创建一个路径

    CGMutablePathRef path=CGPathCreateMutable();

    CGPathMoveToPoint(path, nil, View_Width/2, 20);

    CGPathAddCurveToPoint(path, nil, View_Width/2-350, View_Height/3, View_Width/2+360, View_Height/3*2, View_Width/2-20, View_Height);

    

    

    animation.path=path;

    animation.duration=10;

    animation.removedOnCompletion=NO;

    animation.fillMode=kCAFillModeForwards;

    //animation.autoreverses=YES;

    //animation.repeatCount=MAXFLOAT;

    //3._layer添加动画

    [_layer addAnimation:animation forKey:nil];

    

    

    CABasicAnimation *animation1=[CABasicAnimation animation];

    animation1.keyPath=@"transform";

    animation1.toValue=[NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 1, 1, 1)];

    //取消反弹

    animation1.removedOnCompletion=YES;

    animation1.fillMode=kCAFillModeForwards;

    

    animation1.duration=10;

    animation1.autoreverses=YES;

    animation1.repeatCount=1;

    //3._layer添加动画

    [_layer addAnimation:animation1 forKey:nil];


}

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


@end


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值