1

I have drawn a circular path for a button (scienceCircle)-

var sciencePath = UIBezierPath()
    sciencePath.moveToPoint(CGPoint(x: 228, y: 132))
    sciencePath.addCurveToPoint(CGPoint(x: 228, y: 132), controlPoint1: CGPoint(x: 208, y: 153), controlPoint2: CGPoint(x: 248, y: 114))
    let anim2 = CAKeyframeAnimation(keyPath: "position")
    anim2.path = sciencePath.CGPath
    anim2.repeatCount = Float.infinity
    anim2.duration = 7.0

scienceCircle.layer.addAnimation(anim2, forKey: "animate position along path")

This is the code I typed to add the button-

var scienceCircle = InterestSubCircles() //A Cocoa Touch Class with a drawRect method to make the button a circle.
scienceCircle.frame = CGRect(x: 183, y: 137, width: 100, height: 100)
self.view.addSubview(scienceCircle)

This button keeps on moving in circles. Now, I cannot press the button when it is moving (when it is displaced). I can only tap it when it is in it's original position. Basically, I cannot tap the button when it is being displaced continuously by the animation. What can I do here? Please help.

Krish Wadhwana
  • 1,544
  • 2
  • 12
  • 24
  • No, I want it to keep moving, Anyways, it is moving very little in its own place. It's an effect in the app, so I don't want to stop animating it. @Aaron – Krish Wadhwana Jul 24 '15 at 16:06
  • Do the animating on a background thread – milo526 Jul 24 '15 at 16:29
  • @KrishWadhwana. Ah, I see. I thought you meant that you couldn't tap the button because you couldn't catch it while it was animating. Your quote: "Basically, I cannot tap the button when it is being displaced continuously by the animation." – Aaron Jul 24 '15 at 16:53
  • So do know how I can fix this? @Aaron – Krish Wadhwana Jul 24 '15 at 17:19
  • Try UIImageView object with Tap Gesture. – Avijit Nagare Jul 24 '15 at 17:39
  • @KrishWadhwana Can you add the code you use to hook up the button tap? Also, what is `InterestSubCircles`? Share the code for that class, as well. – Aaron Jul 24 '15 at 17:45

0 Answers0