0

我正在使用UIBezierPath该类绘制一个多边形。

我有多边形列表。现在,当我单击任何多边形时,我想检测它是哪个多边形。我认为您可以在 中看到相同的概念UIMapView

4

1 回答 1

0

这个怎么样?。

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{

    CGPoint p = [[touches anyObject] locationInView:self.view];

   // UIBezierPath *pathTodetect; Path of the shape that you want to detect. In a for loop you can check for all possible paths. 

    if(CGPathContainsPoint(pathTodetect.CGPath,nil, p, NO))
    {    

        NSLog(@"touched.");
        // the touch is inside the shape  
    }   

}
于 2012-02-13T08:43:41.823 回答