1
我有一個藍色圓圈的圖像,我想使它在橢圓路徑中連續循環。我首先創建了一個圓形路徑,並且它是成功的,但是創建一個橢圓形路徑循環該圓形,但在它再次循環之前暫時停止。有沒有什麼我錯過了沒有猶豫讓橢圓形路徑循環。這是兩個循環的代碼。Swift:使圖像在UIBezierPath中不斷循環(overInRect)
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")
}