2012-05-04 20 views
5

he dibujado tantos arco mediante el siguiente código:obtener el punto táctil en el arco dibujado por CGContext

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

Ahora quiero que cuando me toque cualquier arco que quiero para detectar lo que de arco ha sido tocado

¿Cómo puedo hacer eso?

+0

usa los métodos anteriores para touch (touchbegan, touchmoved, toucheended) para detectar en qué parte de la pantalla se produjo el toque y luego busca lo que está cerca. – SpaceDog

Respuesta

0

Se puede hacer así:

1.Add su arco a un camino,

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

verás el " Toca el arco ". iniciar sesión cuando toque el arco.

Cuestiones relacionadas