我有一个Array[CGPoint]
的函数,我试图创建一个趋势。我无法通过点阵列使其成为平滑线,当我在每个点之后使用moveToPoint()
函数时,我在后台得到这条黑线。这是我输出的代码和图像:
class func drawLineThroughPoint(start : CGPoint, throughPoint through: [CGPoint], endPoint end:CGPoint, ofColor lineColor: UIColor, inView view:UIView) {
//design the path
let path = UIBezierPath()
path.moveToPoint(start)
for (_, point) in EnumerateSequence(through) {
path.addLineToPoint(point)
//path.moveToPoint(point) MARK: See image with moveToPoint
path.moveToPoint(point) //MARK: See image without moveToPoint
}
path.addLineToPoint(end)
//design path in layer
//design path in layer
let shapeLayer = CAShapeLayer()
shapeLayer.path = path.CGPath
shapeLayer.strokeColor = lineColor.CGColor
shapeLayer.shadowColor = lineColor.CGColor
shapeLayer.shadowOffset = CGSize(width: 0, height: 2)
shapeLayer.shadowOpacity = 0.95
shapeLayer.shadowRadius = 5
shapeLayer.fillColor = UIColor.clearColor().CGColor
shapeLayer.lineJoin = kCALineJoinRound
shapeLayer.lineCap = kCALineCapRound
shapeLayer.lineWidth = 10.0
view.layer.addSublayer(shapeLayer)
}
使用path.moveToPoint()
没有path.moveToPoint()