我希望能够实时应用一条线。所以我想不断为Bezier曲线添加值。为了测试它,我正在做:
import UIKit
class TestView: UIView {
var arr = [CGPointMake(0, 0), CGPointMake(120, 150), CGPointMake(260, 150), CGPointMake(210, 30)]
var control = CGPointMake(5, 5)
let path = UIBezierPath()
var count = 0
override func drawRect(rect: CGRect) {
path.lineWidth = 3.0
path.moveToPoint(CGPointMake(20, 40))
path.addQuadCurveToPoint(arr[1], controlPoint: control)
path.stroke()
var timer = NSTimer.scheduledTimerWithTimeInterval(2.0, target: self, selector: Selector("update"), userInfo: nil, repeats: true)
}
func update() {
var p = arr[count]
path.addQuadCurveToPoint(p, controlPoint: control)
path.stroke()
count++
}
}
我会清理它,但这似乎不起作用。它绘制了初始线,但是没有添加任何其他点。
有更好的方法吗?
答案 0 :(得分:1)
有几点可以帮助你找到正确的方向:
希望这有帮助!