2012-05-04 9 views
5

ho tratto tanti arco usando sottostante Codice:ottenere il punto di tocco a Arc disegnato da CGContext

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

Ora voglio che quando tocco qualsiasi arco che voglio rilevare ciò che l'arco è stato toccato

Come posso farlo?

+0

utilizzare i vecchi metodi per il tocco (touchbegan, touchmoved, toucheended) per rilevare dove nella schermata si è verificato il tocco, quindi cercare ciò che è vicino. – SpaceDog

risposta

0

Si può fare in questo modo:

1.Add vostro arco ad un percorso,

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

vedrete la " Tocca l'arco. " log quando tocco arco.

Problemi correlati