【问题标题】:Making UIBezierPath more like NSBezierPath with elementCount and elementAtIndex使用 elementCount 和 elementAtIndex 使 UIBezierPath 更像 NSBezierPath
【发布时间】:2014-08-07 02:36:32
【问题描述】:

在将一些 Cocoa 代码移动到 Cocoa Touch 时,我很失望地发现 UIBezierPath 缺少“访问路径元素”方法:

– elementCount
– elementAtIndex:
– elementAtIndex:associatedPoints:
– removeAllPoints
– setAssociatedPoints:atIndex:

在 Cocoa Touch 中获取这些元素的唯一方法似乎是通过CGPathApply。在我尝试将其重新创建为 UIBezierPath 的子类或类别之前,我想知道这是否已经完成。有没有人知道这样的东西是否已经可用?

【问题讨论】:

标签: iphone ios cocoa-touch uibezierpath


【解决方案1】:

我在https://github.com/seivan/UIBezierPathPort 上创建了一个端口,但它使用的是 Swift。 有一个测试套件和文档。 从 Beta 5 开始工作。

从技术上讲,您应该能够在 Obj-C 项目中使用 Swift。

让我知道你喜欢它。

【讨论】:

    【解决方案2】:

    几个月前我遇到了同样的问题,当时找不到任何现成的东西。 (说实话,因为走CGPathApply 路线对我的需求来说并没有那么糟糕,所以说实话我看起来并不难)。

    CGPath 中的每个CGPathElement 调用applier 函数,这样的元素由CGPathElementTypeCGPoints 的C 数组组成。

    因为CGPathElementType 是一个只有五个不同值的枚举

    enum CGPathElementType {
       kCGPathElementMoveToPoint,
       kCGPathElementAddLineToPoint,
       kCGPathElementAddQuadCurveToPoint,
       kCGPathElementAddCurveToPoint,
       kCGPathElementCloseSubpath
    };
    

    您不需要编写那么多代码来执行(控制)点操作/检查路径。不过,拥有相同的界面会很好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-05
      • 1970-01-01
      • 2019-07-17
      相关资源
      最近更新 更多