In Swift 4.2 under iOS 12 beta 12 I would like to get the current position of a dot I have animated along a path in a CAKeyframeAnimation
.
The code for the animation is this:
@IBOutlet weak var dot: UIImageView!
func animateDot() {
// Oval path.
let ovalWidth = UIScreen.main.bounds.width * 0.7
let ovalHeight = UIScreen.main.bounds.height * 0.75
let ovalPath = UIBezierPath(ovalIn: CGRect(x: -ovalWidth / 2 , y: -ovalHeight / 2, width: ovalWidth, height: ovalHeight))
let orbit = CAKeyframeAnimation(keyPath: "position")
orbit.path = ovalPath.cgPath
orbit.duration = CFTimeInterval(2.5)
orbit.isAdditive = true
orbit.repeatCount = 6
orbit.calculationMode = kCAAnimationPaced
orbit.rotationMode = kCAAnimationRotateAuto
self.dot.layer.add(orbit, forKey: "orbit")
}
My question is: once this is launched and running, how can I query the animation in Swift to get the current screen xy of the center of the dot?