3 回答
TA贡献2037条经验 获得超6个赞
为了找到一个像雨燕解决方案,我在这整个的做法strumbled 后实施了CGPath扩展像这样得到的路径点:
extension CGPath {
func points() -> [CGPoint]
{
var bezierPoints = [CGPoint]()
self.forEach({ (element: CGPathElement) in
let numberOfPoints: Int = {
switch element.type {
case .MoveToPoint, .AddLineToPoint: // contains 1 point
return 1
case .AddQuadCurveToPoint: // contains 2 points
return 2
case .AddCurveToPoint: // contains 3 points
return 3
case .CloseSubpath:
return 0
}
}()
for index in 0..<numberOfPoints {
let point = element.points[index]
bezierPoints.append(point)
}
})
return bezierPoints
}
func forEach(@noescape body: @convention(block) (CGPathElement) -> Void) {
typealias Body = @convention(block) (CGPathElement) -> Void
func callback(info: UnsafeMutablePointer<Void>, element: UnsafePointer<CGPathElement>) {
let body = unsafeBitCast(info, Body.self)
body(element.memory)
}
let unsafeBody = unsafeBitCast(body, UnsafeMutablePointer<Void>.self)
CGPathApply(self, unsafeBody, callback)
}
}
- 3 回答
- 0 关注
- 734 浏览
添加回答
举报