2017-01-03 3 views
0

Guys J'ai le code suivant pour produire un bezierpathAnimer roundedRect avec CoreAnimation

firstLine.path = UIBezierPath(roundedRect: CGRect(x: frameSize.width/2.2, y: frameSize.height/2.6, width: 4, height: 4), cornerRadius: 10).cgPath 

J'essaie d'animer le firstLine en le déplaçant vers la droite de l'écran par la valeur x et revenir à la position initiale. Mais je ne sais pas quoi utiliser pour le keyPath dans l'animation.

let animation = CABasicAnimation(keyPath: "??") 
animation.toValue = // this should be the position to move? 
animation.duration = 0.5 // duration of the animation 
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut) // animation curve is Ease Out 
animation.fillMode = kCAFillModeBoth // keep to value after finishing 
animation.isRemovedOnCompletion = false // don't remove after finishing 
animation.autoreverses = true 
animation.repeatCount = HUGE 

que quelqu'un peut me aider sur ce :)

Répondre

1

De: https://developer.apple.com/reference/quartzcore/cabasicanimation

Vous créez une instance de CABasicAnimation en utilisant l'initialisation héritée (KeyPath :) méthode, spécifiant le chemin clé la propriété à animer dans l'arbre de rendu.

Exemple de ce que vous voulez:

let animation = CABasicAnimation(keyPath: "position") 
animation.fromValue = [startX, startY] 
animation.toValue = [destinationX, destinationY] 
+0

La keypath position est en quelque sorte ne fonctionne pas pour bezierpath. – Reshad

+0

@Reshad Pouvez-vous ajouter le code que vous utilisez pour déplacer le Bézier? –