IOS Core Animation动画

1、要实现动画效果,首先初始化CALayer 

    CAlayer *layer=[[CALayer alloc]init];

    layer.frame=CGRectMake(20, 20, 15, 30);

    [self.view.layer addSublayer:layer];

    _mlayer.contents=(id)[UIImage imageNamed:@"petal"].CGImage;

2、移动layer的position

    CABasicAnimation 

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

    初始位置

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

    移动后位置CGPoint *point

    animation.toValue=[NSValue valueWithCGPoint:point];

3、旋转layer

    CABasicAnimation *rotateAnimationY=[CABasicAnimation animationWithKeyPath:@"transform.rotation"];

    初始角度

    rotateAnimationY.fromValue=[NSNumber numberWithFloat:0];

    旋转后位置

    rotateAnimationY.toValue=[NSNumber numberWithFloat:10*M_PI];

4、组合   把之前的所有动画组合在一起

    开始组合

    CAAnimationGroup *group=[CAAnimationGroup animation];

    layer.position=point;(这个才可以设置动画结束后的位置)

    //设置播放速度

    group.speed=0.1;

    group.fillMode=kCAFillModeForwards;(这个的几个Mode还不知道有什么作用,哪位大神路过可以给我教教

    将需要组合的动画对象打包数组中

    group.animations=[NSArray arrayWithObjects:animation,rotateAnimationY ,nil];

   开始动画

    [_mlayer addAnimation:group forKey:@"_mLayerMvoe"];

属性:

autoreverses设置为YES时,动画结束后动画的返回到原来的位置

duration  动画的持续时间

speed 动画速度 默认为1.0 会影响duration

repeatCount  重复次数 默认为0 播放一次

 

 

转载于:https://my.oschina.net/shuaishuaihui/blog/741201

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值