//移动
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"];
本文介绍如何使用Core Animation在iOS应用中实现元素的无限循环移动与旋转动画效果。通过设置CABasicAnimation并调整其属性,可以轻松实现流畅的动画体验。
389

被折叠的 条评论
为什么被折叠?



