Aak*_*ani 5 iphone objective-c cgcontext
我使用下面的代码绘制了这么多弧:
CGContextAddArc(context,
e.x,
e.y,
Distance/2,
M_PI+angle1,
angle1,
aClock);
CGContextStrokePath(context)
Run Code Online (Sandbox Code Playgroud)
现在我希望当我触摸任何拱形时,我想要检测到哪个弧被触摸过
我怎样才能做到这一点?
你可以这样做:
1.将弧添加到路径中,
_path = CGPathCreateMutable();
CGPathAddArc(_path, NULL, e.x, e.y, Distance/2, M_PI + angle1, angle1, aClock);
CGContextAddPath(context, _path);
CGContextStrokePath(context);
Run Code Online (Sandbox Code Playgroud)
2.重写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);
}
}
Run Code Online (Sandbox Code Playgroud)
您会看到“触摸弧”。记录触摸弧时的情况。