Touch event on a quartz circle pattern?

I drew a circle on the iphone simulator using quartz 2d with filling. Is there any way I can detect a touch event on this circle?

Thanks Harikant Jammy

+3
source share
3 answers

If you have the CGPath of this circle, you can get CGPoint, where the user's finger has got inside touchsBegan and check if he gets into this CGPath using the following code.

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
  UITouch *touch = [[event allTouches] anyObject];
  CGPoint location = [touch locationInView:self.view];
  // Depending on your code, you may need to check a different view than self.view

  // You should probably check the docs for the arguments of this function--
  // It been a while since I last used it
  if (CGPathContainsPoint(yourCircle, nil, location, nil)) {
    // Do something swanky
  } else {
    // Don't do teh swank
  }
}
+7
source

I have not tested it, but if the surrounding space around the circle is set to alpha 0, then perhaps only the circle will take touch. You may have to disable isOpaque for the view and not have a background color.

, , , .

0

Just place a custom invisible button with 0.0 alpha on this circle so that the button can always recognize the touch.

0
source

Source: https://habr.com/ru/post/1717343/


All Articles