터치 이벤트를 처리하기 위해 CALayer가 포함 된 UIView를 사용해야하며 CALayers의 Touch 이벤트는 내장되어 있지 않습니다. - (CALayer *)hitTest:(CGPoint)thePoint
은 터치 이벤트의 포인트가있는 "가장 깊은"CALayer를 반환합니다. 당신이 [self.layer hitTest:point]
를 호출하는 경우 그래서, 그것은 모든 하위 레이어를 확인하고 CGPath 당신이 그것으로 공급되는 점에서 얻을 수있는 방법은 없습니다 올바른 CALayer
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
CGPoint point = [[touches anyObject] locationInView:self];
CALayerSubclass *taplayer = [self.layer hitTest:point]
NSArray *points = [taplayer getPoints];
}
반환합니다. 경로에서 정보를 가져 오는 것에 대한 최선의 답변은 these methods입니다. 그래서, 말했듯이, 최선의 방법은 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]];
...
}
그냥 NSValue 모든 CGPoints (또는 대부분의 다른 코어 그래픽 구조)를 저장하고 배열로 던져.
실제로 경로 그림이 들어있는 CALayer에서 모든 점을 검색하려고합니다. 그렇게하는 방법? – Harsh
죄송합니다. 죄송합니다. 귀하의 질문을 읽지 마십시오. 희망하는 나의 편집 도움. – Kevin
-drawInContext :는 CAShapeLayer에서 호출되지 않습니다. –