Cocoa touch containsPoint不';你不能和现金支付员一起工作吗?

Cocoa touch containsPoint不';你不能和现金支付员一起工作吗?,cocoa-touch,uikit,core-graphics,quartz-graphics,cashapelayer,Cocoa Touch,Uikit,Core Graphics,Quartz Graphics,Cashapelayer,在UIView的主层中有两个Cashape层。 CAShapeLayers具有复杂的形状,我需要知道是否在形状边界内接触到一个点。另外,我需要知道哪个形状被碰过 我正在尝试containsPoint,但没有任何效果。在我的头撞了两天后,我能够生成这个奇怪的代码,看起来它正在工作 目标是击中测试层。CAShapeLayer在屏幕上移动,因此形状不是固定的。测试CGPath currentPoint并不简单 请随意添加任何输入 -(void)touchesBegan:(NSSet *)touches

在UIView的主层中有两个Cashape层。 CAShapeLayers具有复杂的形状,我需要知道是否在形状边界内接触到一个点。另外,我需要知道哪个形状被碰过


我正在尝试containsPoint,但没有任何效果。

在我的头撞了两天后,我能够生成这个奇怪的代码,看起来它正在工作

目标是击中测试层。CAShapeLayer在屏幕上移动,因此形状不是固定的。测试CGPath currentPoint并不简单

请随意添加任何输入

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { CGPoint p = [[touches anyObject] locationInView:self]; CGAffineTransform transf = CGAffineTransformMakeTranslation(-shapeLayer.position.x, -shapeLayer.position.y); if(CGPathContainsPoint(shapeLayer.path, &transf, p, NO)){ // the touch is inside the shape } } -(无效)触摸开始:(NSSet*)触摸事件:(UIEvent*)事件 { CGPoint=[[toucheanyobject]locationInView:self]; CGAffineTransform transf=CGAffineTransformMakeTransform(-shapeLayer.position.x,-shapeLayer.position.y); if(CGPathContainsPoint(shapeLayer.path,&transf,p,NO)){ //触摸在形状内部 } }
CGPathContainsPoint()
是一个作用于
CGPath
对象的函数。它不关心(或不知道)此路径是
CAShapeLayer
的一部分,还是通过核心图形调用手动绘制的。请出示您的密码。