3

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 Image

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?

Here is my code for the animation (that don't work):

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")
  • Try adapting [this answer](http://stackoverflow.com/a/13667092/77567). – rob mayoff Jun 24 '16 at 23:43
  • Thanks @robmayoff, I don't get obj-c, can you tell me how would the first part of the _typealias_ and the extension would look like. I don't get why there are the h file and m. Thanks. Don't worry I could figure out the other parts – Andres Leal Jun 25 '16 at 01:02
  • 2
    Learning a little Objective-C is the single best thing you can do to make yourself a better iOS programmer, because of the amount of iOS programming information that's only available in Objective-C (like for example the answer I linked). – rob mayoff Jun 25 '16 at 02:07

0 Answers0