在石英圆图上触摸事件?

问题描述:

我已经使用石英2d填充iPhone模拟器上绘制了一个圆圈。有什么方法可以检测到该圆上的触摸事件?在石英圆图上触摸事件?

感谢 Harikant Jammi

我没有测试它,但如果绕了一圈周围的空间设置为0的α,那么也许只有圈子会接受触摸。您可能必须关闭视图的isOpaque,并且没有背景颜色。

如果这不起作用,那么你将不得不处理水龙头的位置,并编写代码,看看它是否在圆形区域内。

只需在该圆上放置一个带有0.0 alpha的自定义不可见按钮,这样按钮将始终能够检测到触摸。

如果您具有该圆圈的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 
    } 
} 
+1

这个答案应该被接受。 – rayfranco 2012-06-16 22:50:16