我有一个蓝色圆圈的图像,我想让它在椭圆路径中连续循环。我首先创建了一个圆形路径,但它成功了,但是创建一个椭圆形路径会循环圆圈,但会在它再次循环之前暂停。是否有一些我缺少的东西使椭圆形路径循环没有犹豫。这是两个循环的代码。
func performRotation(){
let path = UIBezierPath(ovalInRect: CGRectMake(50, 50, 220, 100))
let anim = CAKeyframeAnimation(keyPath: "position")
anim.path = path.CGPath
anim.rotationMode = kCAAnimationLinear
anim.repeatCount = Float.infinity
anim.duration = 5.0
//@IBOutlet weak var ball: UIImageView!
ball.layer.addAnimation(anim, forKey: "animate position along path")
//this is the circle path that loops without the stutter
// let ovalStartAngle = CGFloat(90.01 * M_PI/180)
// let ovalEndAngle = CGFloat(90 * M_PI/180)
// let ovalRect = CGRectMake(97.5, 58.5, 125, 125)
//let path = UIBezierPath()
//path.moveToPoint(CGPoint(x: 200, y: 150))
//path.addArcWithCenter(CGPointMake(CGRectGetMidX(ovalRect), CGRectGetMidY(ovalRect)),
//radius: CGRectGetWidth(ovalRect) / 2,
//startAngle: ovalStartAngle,
//endAngle: ovalEndAngle, clockwise: true)
//let anim = CAKeyframeAnimation(keyPath: "position")
//anim.path = path.CGPath
//anim.rotationMode = kCAAnimationLinear
//anim.repeatCount = Float.infinity
//anim.duration = 5.0
//ball.layer.addAnimation(anim, forKey: "animate position along path")
}
答案 0 :(得分:0)
尝试设置calculateMode,
,而不是设置rotationModeanim.calculationMode = kCAAnimationPaced