2d动画

原创
2016/09/01 19:41
阅读数 9

//初始化

    _layer=[[CALayer alloc]init];

    _layer.contents=(__bridge id _Nullable)([UIImage imageNamed:@"1.jpg"].CGImage);

    _layer.backgroundColor=[UIColor orangeColor].CGColor;

    //设定它的from值

    _layer.frame=CGRectMake(10, 10, 100, 100);

    [self.view.layer addSublayer:_layer];

    

    //移动layer的position

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

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

    CGPoint point=_layer.position;

    point.x +=200;

    point.y +=300;

    animation.toValue=[NSValue valueWithCGPoint:point];

    

    //以x轴进行旋转

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

    rotationAnimation.fromValue=[NSNumber numberWithFloat:100.0];

    rotationAnimation.toValue=[NSNumber numberWithFloat:6.0*M_PI];

    

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

    rotationAnimationI.fromValue=[NSNumber numberWithFloat:100.0];

    rotationAnimationI.toValue=[NSNumber numberWithFloat:6.0*M_PI];

    //对layer进行缩放

    CABasicAnimation*scaoleAnimation=[CABasicAnimation animationWithKeyPath:@"transfrom.scale.x"];

    scaoleAnimation.duration=3.0;

    scaoleAnimation.autoreverses=YES;

    scaoleAnimation.fromValue=[NSNumber numberWithFloat:10.0];

    scaoleAnimation.toValue=[NSNumber numberWithFloat:6.0*M_PI];

    scaoleAnimation.fillMode=kCAFillModeBackwards;

    //把上面的动画组合起来

    CAAnimationGroup*group=[CAAnimationGroup animation];

    //设置它到达指定位置后返回到开始的值

    group.autoreverses=YES;

    //完成后反向完成

    group.duration=3.0;

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

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

无限播放    

    group.repeatCount=HUGE_VALF;

        [_layer addAnimation:group forKey:@"_layerMove"];

 

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部