title: Move object with finger following path [Swift]
body: <p>I have a circle in my view, With a little oval that can be moved around that big circle, the idea of moving the little oval is to change the time on the clock. I am trying to move the oval but only by following the path so it won't get out of the circle. As if it was a rail road and the train only follows the rail roads but at the time follows the finger position.
  Here I attach the image <a href="http://i.stack.imgur.com/Cv74U.png" rel="nofollow">Image</a></p>
  
  <p>I tried creating an animation, and maybe use that animation to then follow the finger. I don't really know how to do this. Any help please?</p>
  
  <p>Here is my code for the animation (that don't work):</p>
  
  <pre><code>let customPath = UIBezierPath()
      customPath.move(to: CGPoint.init(x: 160, y: 165))
      customPath.addLine(to: CGPoint.init(x: 260, y: 245))
      customPath.addLine(to: CGPoint.init(x: 165, y: 365))
      customPath.addLine(to: CGPoint.init(x: 60, y: 260))
  
      let movingImage = UIImage(named: "MoveOval")
      let movingLayer = CALayer()
      movingLayer.anchorPoint = CGPoint.zero
      movingLayer.contents = moveOval
      movingLayer.frame = CGRect.init(x: 0.0, y: 0.0, width: (movingImage?.size.width)!, height: (movingImage?.size.height)!)
      self.view.layer.addSublayer(movingLayer)
  
      let pathAnimation = CAKeyframeAnimation(keyPath: "anim")
      pathAnimation.duration = 4.0
      pathAnimation.path = customPath.cgPath
      pathAnimation.calculationMode = kCAAnimationLinear
      movingLayer.add(pathAnimation, forKey: "anim")
  </code></pre>