タッチイベントを処理するには、CALayerを含むUIViewを使用する必要があります。CALayersには組み込みのタッチイベントはありません。- (CALayer *)hitTest:(CGPoint)thePoint
タッチイベントからのポイントが含まれる「最も深い」CALayerを返します。したがって、呼び出す[self.layer hitTest:point]
と、すべてのサブレイヤーがチェックされ、正しいものが返されますCALayer
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
CGPoint point = [[touches anyObject] locationInView:self];
CALayerSubclass *taplayer = [self.layer hitTest:point]
NSArray *points = [taplayer getPoints];
}
CGPathに入力したポイントから抜け出す方法はありません。あなたができる最善のことは、パスから情報を取得することについてのこれらの方法です。したがって、あなたが言ったように、最善の策は、CALayerをサブクラス化し、後で取得するために必要なすべての情報をデータ構造に入れることです。
// .h
@interface CALayerSubclass : CALayer
@property (nonatomic, strong) NSMutableArray *points;
@end
// .m
-(void)drawInContext:(CGContextRef)ctx {
...
[bezierPath addCurveToPoint:controlPoint1:point1 controlPoint2:point2];
[points addObject:[NSValue valueWithCGPoint:point1]];
[points addObject:[NSValue valueWithCGPoint:point2]];
...
}
すべてのCGPoint(または他のほとんどのコアグラフィックス構造)をNSValueに格納し、それを配列にスローするだけです。