最近在做ios畫板,使用CGContext模擬繪畫,然而出現高低版本的問題,在此記錄。
貼出一段畫在context上面的函數代碼
override func drawInContext(context: CGContext) {
if let lastPoint = self.lastPoint {
context.move(to: CGPoint(x: lastPoint.x, y: lastPoint.y))
context.addLine(to: CGPoint(x: endPoint.x, y: endPoint.y))
} else {
context.move(to: CGPoint(x: beginPoint.x, y: beginPoint.y))
context.addLine(to: CGPoint(x: endPoint.x, y: endPoint.y))
}
}
CGContextRef改爲CGContext,所有的move和add line 的方法更加人性化,作爲參數很拆分即可