【问题标题】:get Touch point in Arc drawn by CGContext获取 CGContext 绘制的 Arc 中的触摸点
【发布时间】:2012-05-04 08:01:02
【问题描述】:

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

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

现在我想要当我触摸任何拱门时,我想检测到哪个拱门被触摸了

我该怎么做?

【问题讨论】:

  • 使用旧的触摸方法(touchbegan、touchmoved、toucheended)检测屏幕上发生触摸的位置,然后查找附近的位置。

标签: iphone objective-c cgcontext


【解决方案1】:

你可以这样做:

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

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

【讨论】:

    猜你喜欢
    • 2012-03-14
    • 1970-01-01
    • 2014-04-18
    • 2011-10-03
    • 1970-01-01
    • 1970-01-01
    • 2012-04-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多