我有一個快速的問題給你們。ShapeLayer HitTest的路徑不適合我
我有一個shapeLayer,我設置了一個框架。 然後我用UIBezierPath在框架內部繪製一個形狀,我將其設置爲shapeLayer.path
問題是,如何檢測形狀中的龍頭內部是真實還是外部形狀爲假?
我一直在嘗試所有的那種瘋狂的東西,但沒有一個是工作
-(Boolean) isPoint:(CGPoint)point InsideShape:(CSAbstractShapeLayer*) shapeLayer fromSuperLayer:(CALayer*) sLayer
{
CGPoint locationPoint = point;
locationPoint = [sLayer convertPoint:locationPoint toLayer:shapeLayer];
CGAffineTransform at = shapeLayer.affineTransform;
return CGPathContainsPoint([shapeLayer path],&at, locationPoint, NO);
}
-(Boolean) isPoint:(CGPoint)point InsideShape:(CSAbstractShapeLayer*) shapeLayer fromSuperLayer:(CALayer*) sLayer
{
CGPoint locationPoint = point;
locationPoint = [sLayer convertPoint:locationPoint toLayer:shapeLayer];
return [[UIBezierPath bezierPathWithCGPath:shapeLayer.path] containsPoint:locationPoint];
}
-(Boolean) isPoint:(CGPoint)point InsideShape:(CSAbstractShapeLayer*) shapeLayer fromSuperLayer:(CALayer*) sLayer
{
CGPoint locationPoint = point;
locationPoint = [sLayer convertPoint:locationPoint toLayer:shapeLayer];
CGRect theRect = CGPathGetBoundingBox(shapeLayer.path);
return CGRectContainsPoint(theRect, locationPoint);
}
注1:看來我不能張貼圖片卻又如此想象裏面對角線一個長方形, 權線的一側是形狀,所以我需要檢測內部的水龍頭內部爲YES和外部(線的左側和矩形外)作爲否
注2:可能會有所幫助,但我無法理解它....我發現,如果你創建一個shapeLayer並向shapeLayer.path添加一個CGPath並且不提供一個框架,那麼框架和框架的邊界即使形狀在屏幕上呈現,因此shapeLayer是[0,0,0,0],因此[view.layer hitTest:point]將不會找到shapeLayer作爲目標。因此,我爲我的shapeLayer提供了一個框架和一個綁定。
非常感謝您的時間!