5

我用下面的代码画了这么多弧线:

CGContextAddArc(context,
                        e.x,
                        e.y,
                        Distance/2,
                        M_PI+angle1,
                        angle1,
                        aClock); 
        CGContextStrokePath(context)

现在我希望当我触摸任何拱门时我想检测到哪个弧被触摸了

我怎样才能做到这一点?

4

1 回答 1

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);
    }
}

您将看到“触摸弧”。触摸弧时记录。

于 2014-05-26T09:09:06.810 回答