swift CGContext改動

 

最近在做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 的方法更加人性化,作爲參數很拆分即可

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章