Ich habe eine UIView, die als Unteransicht zu meinem View-Controller hinzugefügt wird. Ich habe einen bezier Pfad für diese Ansicht gezeichnet. Meine drawRect Implementierung ist unterErkennung von Tap in einem Bezier-Pfad
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
UIBezierPath *bpath = [UIBezierPath bezierPath];
[bpath moveToPoint:CGPointMake(50, 50)];
[bpath addLineToPoint:CGPointMake(100, 50)];
[bpath addLineToPoint:CGPointMake(100, 100)];
[bpath addLineToPoint:CGPointMake(50, 100)];
[bpath closePath];
CGContextAddPath(context, bpath.CGPath);
CGContextSetStrokeColorWithColor(context,[UIColor blackColor].CGColor);
CGContextSetLineWidth(context, 2.5);
CGContextStrokePath(context);
UIColor *fillColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.5 alpha:0.7];
[fillColor setFill];
[bpath fill];
}
I Hahn in diesem Bezierpfad erkennen wollen, aber nicht der Punkt, der innerhalb des UIView und außerhalb des Weges ist. Zum Beispiel in diesem Fall, wenn meine Berührungskoordinate (10, 10) ist, sollte sie nicht erkannt werden. Ich weiß über CGContextPathContainsPoint, aber es hilft nicht, wenn Berührung innerhalb des Pfades ist. Gibt es eine Möglichkeit, Berührungsereignisse innerhalb des Bezier-Pfads zu erkennen?
Vielleicht müssen Sie 'CGPathCloseSubpath' hinzufügen. Ich habe meine Antwort aktualisiert. Bitte prüfe. – Avt
"detect tap innerhalb dieses Bezier-Pfades nicht innerhalb der UIView" Dieser Bezier-Pfad wird in der UIView gezeichnet, also wie kann ein Tap in ihm sein, aber nicht in der UIView? – matt
@matt: bearbeitet die Frage – blancos