2012-05-04 34 views
5
繪製弧形觸摸點

我已提請使用下面的代碼這麼多弧線:獲得通過CGContext上

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

現在我想,當我接觸任何拱我要檢測一個已經被弧線感動

我該怎麼做?

+0

使用舊方法進行觸摸(touchbegan,touchmoved,toucheended)來檢測屏幕中觸摸發生的位置,然後查看接近的內容。 – SpaceDog

回答

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

你會看到「觸摸弧線「。記錄觸摸弧度。