CABasicAnimation

    //移动

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

    translation.fromValue = [NSValue valueWithCGPoint:CGPointMake(24, 240)];

    translation.toValue = [NSValue valueWithCGPoint:CGPointMake(320- 24, 240)];

    translation.duration = 2;

    translation.repeatCount = HUGE_VALF;

    translation.autoreverses = YES;

 

    //转动

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

    //kCAMediaTimingFunctionLinear 表示时间方法为线性,使得足球匀速转动

    rotation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];

    rotation.toValue = [NSNumber numberWithFloat:4 * M_PI];

    rotation.duration = 2;

    rotation.repeatCount = HUGE_VALF;

    rotation.autoreverses = YES;

 

    [soccer.layer addAnimation:rotation forKey:@"rotation"];

    [soccer.layer addAnimation:translation forKey:@"translation"];

你可能感兴趣的:(animation)