我使用下面的代码绘制了很多弧:
CGContextAddArc(context,
e.x,
e.y,
Distance/2,
M_PI+angle1,
angle1,
aClock);
CGContextStrokePath(context)
现在我希望当我触摸任何拱形时,我想要检测哪个弧被触摸
我该怎么做?
答案 0 :(得分:0)
你可以这样做:
1.将你的弧线加到一条路上,
_path = CGPathCreateMutable();
CGPathAddArc(_path, NULL, e.x, e.y, Distance/2, M_PI + angle1, angle1, aClock);
CGContextAddPath(context, _path);
CGContextStrokePath(context);
2.rewrite touchesBegan:withEvent:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSSet *allTouches = [event allTouches];
UITouch *touch = [allTouches anyObject];
CGPoint point = [touch locationInView:[touch view]];
if (CGPathContainsPoint(_path, NULL, point, NO)) {
NSLog(@"point:(%f, %f), Touch arc.", point.x, point.y);
}
else {
NSLog(@"point:(%f, %f), Touch other.", point.x, point.y);
}
}
你会看到“触控弧”。触摸弧时记录。