我從這段代碼中得到了大量的CGContextDrawPath: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
錯誤。它在SKScene中執行。基本上,我在屏幕上以SKShapeNode的形式獲取用戶的繪圖。然後我用Core Graphics的圓圈填充繪圖的路徑。然而,代碼運行緩慢,並給我噸錯誤。我對Swift很陌生。你能幫助我瞭解發生了什麼事嗎?我如何加快速度?我怎麼能給CoreGraphics適當的上下文?CoreGraphics將結果繪製到CGContextDrawPath:無效的上下文0x0
let boundingBox = createdShape.frame
for j in stride(from: Int(boundingBox.minX), to: Int(boundingBox.maxX), by: 10) {
for i in stride(from: Int(boundingBox.minY), to: Int(boundingBox.maxY), by: 10) {
//for i in 0..<10 {
counter += 1
//let originalPoint = CGPoint(x: ((boundingBox.maxX - boundingBox.minX)/2)+boundingBox.minX, y: (boundingBox.maxY-CGFloat(i*10)))
//let originalPoint = CGPoint(x: CGFloat(j), y: (boundingBox.maxY-CGFloat(i*10)))
let originalPoint = CGPoint(x: CGFloat(j), y: (CGFloat(i)))
let point:CGPoint = self.view!.convert(originalPoint, from: self)
if (createdShape.path?.contains(createdShape.convert(originalPoint, from: self)))! {
let circlePath = UIBezierPath(arcCenter: point, radius: CGFloat(5), startAngle: CGFloat(0), endAngle:CGFloat(M_PI * 2), clockwise: true)
circlePath.fill()
let shapeLayer = CAShapeLayer()
shapeLayer.path = circlePath.cgPath
shapeLayer.fillColor = UIColor(red: 180/255, green: 180/255, blue: 180/255, alpha: 0.4).cgColor
shapeLayer.strokeColor = UIColor(red: 180/255, green: 180/255, blue: 180/255, alpha: 0.4).cgColor
shapeLayer.lineWidth = 0.0
view!.layer.addSublayer(shapeLayer)
}
}
}
好吧,看起來你正在混合2種不同的技術在這裏,你讓自己感到困惑。你不想處理核心圖形, – Knight0fDragon