【问题标题】:CAShapeLayer Line drawingCAShapeLayer 画线
【发布时间】:2013-05-16 03:19:09
【问题描述】:

我正在使用CAShapeLayer 从一个位置到另一个位置(X,Y axis) 绘制超过 5 个自定义 uiview(如 UITableView 行)的线。

我的问题是我想知道CAShapeLayer(在我的情况下为行)当前处于什么视图。CALayerCGRect 等是否有CGIntersect?我正在尝试使用核心动画而不是任何图表 API 创建图形。

【问题讨论】:

    标签: iphone uiview core-animation intersection cashapelayer


    【解决方案1】:

    您可以通过检查路径边界框与其他图层框架的交集来检查形状图层是否与特定图层相交。

    BOOL doesIntersect = CGRectIntersectsRect(CGPathGetBoundingBox(path), layer.frame);
    

    【讨论】:

    • 感谢您的回复大卫。但是这行代码使我的应用程序崩溃。我有一个 CAShapeLayer,我想与一些 uiview 帧匹配,无论 CAShapeLayer 是否出现在该特定帧上。
    • @york 你知道路径不是形状,对吧?这是路径。 CGPathRef path = shapeLayer.path;
    • 这是我使用的代码 CGMutablePathRef pointPath = CGPathCreateMutable(); CGPathMoveToPoint(pointPath, NULL, 20, 25); CGPathAddLineToPoint(pointPath, NULL, 30, 35); CGPathAddLineToPoint(pointPath, NULL, 40,45); CGPathAddLineToPoint(pointPath, NULL, 80,115); pathAnimation.path = pointPath; myLayer = [[CAShapeLayer alloc] init]; myLayer.path = 点路径; myLayer.strokeColor = [[UIColor greenColor] CGColor]; myLayer.lineWidth = 4.0; myLayer.lineJoin = kCALineJoinBevel; [self.layer addSublayer:myLayer]; //在自定义视图中添加图层
    • 是的,它是路径而不是形状。现在我想检查 myLayer 是否与我的自定义视图相交。
    • (__bridge CGPathRef)(myLayer) 是一个层,而不是一个路径......你应该得到路径(正如我上面所说的)。这就是为什么我将变量称为“路径”
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-20
    • 1970-01-01
    • 2012-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多