Sto usando questo codice per spostare un UIImage lungo una curva:Swift: spostare UIImage in parte lungo il percorso
// paint curve for sun
let path = UIBezierPath()
let imageSunName = "small_sun.png"
let imageSun = UIImage(named: imageSunName)
let imageView = UIImageView(image: imageSun!)
imageView.frame = CGRect(x: xStart, y: yStart, width: 24, height: 24)
self.view.addSubview(imageView)
path.moveToPoint(CGPoint(x: xStart,y: yStart))
path.addQuadCurveToPoint(CGPoint(x: xEnd, y: yEnd), controlPoint: CGPoint(x: xMiddleTop, y: yMiddleTop))
let animation = CAKeyframeAnimation(keyPath: "position")
animation.path = path.CGPath
animation.repeatCount = 0
animation.duration = 5.0
imageView.layer.addAnimation(animation, forKey: "animate position along path")
Tuttavia, rimangono due problemi:
- vorrei spostare l'immagine solo in parte lungo il percorso (in base al tempo corrente vs alba/tramonto) - come può essere fatto?
- L'immagine passa alla sua posizione di origine dopo l'interruzione dell'animazione - come posso evitare questo?
Acclamazioni
Questa soluzione ha funzionato bene, grazie – AntonSack