石英圆绘图上的触摸事件?

Har*_*mmi 3 iphone

我在iphone模拟器上画了一个圆圈,使用石英2d和填充.有没有办法可以检测到该圈子上的触摸事件?

谢谢Harikant Jammi

Jac*_*cob 7

如果您有该圆的CGPath,则可以获取用户手指落入touchesBegan内部的CGPoint,并使用以下代码检查它是否属于此CGPath.

- (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's been a while since I last used it
  if (CGPathContainsPoint(yourCircle, nil, location, nil)) {
    // Do something swanky
  } else {
    // Don't do teh swank
  }
}
Run Code Online (Sandbox Code Playgroud)