我正在使用Drawing class drawing straight lines instead of curved lines的扩展来插值u形图。不幸的是,这条道路以一种奇怪的方式被关闭了:
应该是什么样的:
它实际上是什么样的:
我的代码:
override func drawRect(rect: CGRect) {
let points: [CGPoint] = [CGPoint(x: 78, y: 99), CGPoint(x: 78, y: 128), CGPoint(x: 78, y: 173), CGPoint(x: 84, y: 199), CGPoint(x: 95, y: 223), CGPoint(x: 112, y: 240), CGPoint(x: 136, y: 243), CGPoint(x: 170, y: 236), CGPoint(x: 203, y: 217), CGPoint(x: 227, y: 190), CGPoint(x: 240, y: 160), CGPoint(x: 241, y: 134), CGPoint(x: 241, y: 108), CGPoint(x: 240, y: 93), CGPoint(x: 239, y: 84), CGPoint(x: 237, y: 75), CGPoint(x: 78, y: 99), CGPoint(x: 78, y: 128), CGPoint(x: 78, y: 173), CGPoint(x: 84, y: 199), CGPoint(x: 95, y: 223), CGPoint(x: 112, y: 240), CGPoint(x: 136, y: 243), CGPoint(x: 170, y: 236), CGPoint(x: 203, y: 217), CGPoint(x: 227, y: 190), CGPoint(x: 240, y: 160), CGPoint(x: 241, y: 134), CGPoint(x: 241, y: 108), CGPoint(x: 240, y: 93), CGPoint(x: 239, y: 84), CGPoint(x: 237, y: 75), CGPoint(x: 78, y: 99), CGPoint(x: 78, y: 128), CGPoint(x: 78, y: 173), CGPoint(x: 84, y: 199), CGPoint(x: 95, y: 223), CGPoint(x: 112, y: 240), CGPoint(x: 136, y: 243), CGPoint(x: 170, y: 236), CGPoint(x: 203, y: 217), CGPoint(x: 227, y: 190), CGPoint(x: 240, y: 160), CGPoint(x: 241, y: 134), CGPoint(x: 241, y: 108), CGPoint(x: 240, y: 93), CGPoint(x: 239, y: 84), CGPoint(x: 237, y: 75)]
let path = UIBezierPath(hermiteInterpolatedPoints: points, closed: false)
if let path = path {
UIColor.blueColor().set()
path.lineWidth = 5.0
path.stroke()
}
}
当数组缩短为:
let points: [CGPoint] = [CGPoint(x: 78, y: 99), CGPoint(x: 78, y: 128), CGPoint(x: 78, y: 173), CGPoint(x: 84, y: 199), CGPoint(x: 95, y: 223), CGPoint(x: 112, y: 240), CGPoint(x: 136, y: 243), CGPoint(x: 170, y: 236), CGPoint(x: 203, y: 217), CGPoint(x: 227, y: 190), CGPoint(x: 240, y: 160), CGPoint(x: 241, y: 134), CGPoint(x: 241, y: 108)]
看起来像这样:
答案 0 :(得分:4)
你的点数是相同的16点重复三次。
let points: [CGPoint] = [
CGPoint(x: 78, y: 99), CGPoint(x: 78, y: 128), CGPoint(x: 78, y: 173), CGPoint(x: 84, y: 199), CGPoint(x: 95, y: 223), CGPoint(x: 112, y: 240), CGPoint(x: 136, y: 243), CGPoint(x: 170, y: 236), CGPoint(x: 203, y: 217), CGPoint(x: 227, y: 190), CGPoint(x: 240, y: 160), CGPoint(x: 241, y: 134), CGPoint(x: 241, y: 108), CGPoint(x: 240, y: 93), CGPoint(x: 239, y: 84), CGPoint(x: 237, y: 75),
CGPoint(x: 78, y: 99), CGPoint(x: 78, y: 128), CGPoint(x: 78, y: 173), CGPoint(x: 84, y: 199), CGPoint(x: 95, y: 223), CGPoint(x: 112, y: 240), CGPoint(x: 136, y: 243), CGPoint(x: 170, y: 236), CGPoint(x: 203, y: 217), CGPoint(x: 227, y: 190), CGPoint(x: 240, y: 160), CGPoint(x: 241, y: 134), CGPoint(x: 241, y: 108), CGPoint(x: 240, y: 93), CGPoint(x: 239, y: 84), CGPoint(x: 237, y: 75),
CGPoint(x: 78, y: 99), CGPoint(x: 78, y: 128), CGPoint(x: 78, y: 173), CGPoint(x: 84, y: 199), CGPoint(x: 95, y: 223), CGPoint(x: 112, y: 240), CGPoint(x: 136, y: 243), CGPoint(x: 170, y: 236), CGPoint(x: 203, y: 217), CGPoint(x: 227, y: 190), CGPoint(x: 240, y: 160), CGPoint(x: 241, y: 134), CGPoint(x: 241, y: 108), CGPoint(x: 240, y: 93), CGPoint(x: 239, y: 84), CGPoint(x: 237, y: 75)
]
你从最后一点CGPoint(x: 237, y: 75)
跳回到开始点CGPoint(x: 78, y: 99)
,(你正在做两次),这就是关闭路径。
该数组的路径是正确的,它重复三次相同的点序列。