iOS 动画(2)

此处设置的动画是对UIImageView的CALayer设置

    _imagelayer = [CALayer layer];
    _imagelayer.cornerRadius =6;
    _imagelayer.borderWidth = 1;
    _imagelayer.borderColor =[UIColor blueColor].CGColor;
    _imagelayer.masksToBounds = YES;
    _imagelayer.frame = CGRectMake(30, 30, 100, 115);
    _imagelayer.contents = (id)[[UIImage imageNamed:@"icon_baiban"]CGImage];
    [self.view.layer addSublayer:_imagelayer];


下面是动画方法

//位移
-(void)move
{
    CGPoint fromPoint = _imagelayer.position;
    CGPoint toPoint = CGPointMake(fromPoint.x +80, fromPoint.y);
    CABasicAnimation *anim =[CABasicAnimation animationWithKeyPath:@"pasition"];
    anim.fromValue =[NSValue valueWithCGPoint:fromPoint];
    anim.toValue = [NSValue valueWithCGPoint:toPoint];
    anim.duration = 0.5;
    _imagelayer.position = toPoint;
    anim.removedOnCompletion = YES;
    [_imagelayer addAnimation:anim forKey:nil];
}
//旋转
-(void)rotate
{
     CABasicAnimation *anim =[CABasicAnimation animationWithKeyPath:@"transform"];
    CATransform3D fromeValue = _imagelayer.transform;
    anim.fromValue = [NSValue valueWithCATransform3D:fromeValue];
    CATransform3D toValue = CATransform3DRotate(fromeValue,  M_PI, 1, 0, 0);
    anim.toValue = [NSValue valueWithCATransform3D:toValue];
    anim.duration = 0.5;
    _imagelayer.transform = toValue;
    anim.removedOnCompletion = YES;
    [_imagelayer addAnimation:anim forKey:nil];
}
//缩放
-(void)scale
{
    CAKeyframeAnimation *anim =[CAKeyframeAnimation animationWithKeyPath:@"transform"];
    anim.values =[NSArray arrayWithObjects:[NSValue valueWithCATransform3D:_imagelayer.transform],[NSValue     valueWithCATransform3D:CATransform3DScale(_imagelayer.transform, 0.2, 0.2, 1)],[NSValue  valueWithCATransform3D:CATransform3DScale(_imagelayer.transform, 2, 2, 1)],[NSValue valueWithCATransform3D:_imagelayer.transform], nil];
    anim.duration =5;
    anim.removedOnCompletion = YES;
    [_imagelayer addAnimation:anim forKey:nil];
}
//动画组
-(void)group
{
    CGPoint fromPoint = _imagelayer.position;
    CGPoint toPoint =CGPointMake(280, fromPoint.y + 200);
    CABasicAnimation *moveAnim =[CABasicAnimation animationWithKeyPath:@"position"];
    moveAnim.fromValue =[NSValue valueWithCGPoint:fromPoint];
    moveAnim.toValue =[NSValue valueWithCGPoint:toPoint];
    moveAnim.removedOnCompletion = YES;
    CABasicAnimation *transform =[CABasicAnimation animationWithKeyPath:@"transform"];
    CATransform3D fromeValue =_imagelayer.transform;
    transform.fromValue =[NSValue valueWithCATransform3D:fromeValue];
    CATransform3D scaleValue = CATransform3DScale(fromeValue, 0.5, 0.5, 1);
    
    CATransform3D rotateValue = CATransform3DRotate(fromeValue, M_PI, 0, 0, 1);
    CATransform3D tovalue =CATransform3DConcat(scaleValue, rotateValue);
    transform.toValue =[NSValue valueWithCATransform3D:tovalue];
    transform.cumulative = YES;
    transform.repeatCount= 2;
    transform.duration = 3;
    CAAnimationGroup *animGroup = [CAAnimationGroup animation];
    animGroup.animations = [NSArray arrayWithObjects:moveAnim,transform, nil];
    animGroup.duration =6;
    [_imagelayer addAnimation:animGroup forKey:nil];
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值