需要支持 Apple Pencil/Finger 在 Swift 上绘图 3
Need Support for Apple Pencil/Finger drawing on Swift 3
我正在使用 swift 2.3 和 TouchCanvas(Apple Pencil 示例应用程序),
其中在绘图时,
我可以在 pen/pencil/brush/eraser - 厚度和颜色之间切换,并且相应地应用相同的内容。
参考:
现在我升级到swift3.0,
在哪张图里,
当在 pen/pencil/brush/eraser - 厚度和颜色之间切换时,最后选择的一个将应用于所有。
参考:
还尝试了最新的苹果 pencil API..结果相同
谁能告诉我这个问题的确切解决方案..
啊啊...经过长时间的尝试...找到了解决方案..
就在 CanvasView.swift
上一行
override func draw(_ rect: CGRect) {
let context = UIGraphicsGetCurrentContext()!
context.setLineCap(.round)
needsFullRedraw = false //Added this line
if (needsFullRedraw) {
setFrozenImageNeedsUpdate()
frozenContext.clear(bounds)
for array in [finishedLines,lines] {
for line in array {
line.drawCommitedPointsInContext(frozenContext, isDebuggingEnabled: isDebuggingEnabled, usePreciseLocation: usePreciseLocations)
}
}
needsFullRedraw = false
}
frozenImage = frozenImage ?? frozenContext.makeImage()
if let frozenImage = frozenImage {
context.draw(frozenImage, in: bounds)
}
for line in lines {
line.drawInContext(context, isDebuggingEnabled: isDebuggingEnabled, usePreciseLocation: usePreciseLocations)
}
}
或者只是评论下面一行
/*if (needsFullRedraw) {
setFrozenImageNeedsUpdate()
frozenContext.clear(bounds)
for array in [finishedLines,lines] {
for line in array {
line.drawCommitedPointsInContext(frozenContext, isDebuggingEnabled: isDebuggingEnabled, usePreciseLocation: usePreciseLocations)
}
}
needsFullRedraw = false
}*/
我正在使用 swift 2.3 和 TouchCanvas(Apple Pencil 示例应用程序),
其中在绘图时,
我可以在 pen/pencil/brush/eraser - 厚度和颜色之间切换,并且相应地应用相同的内容。
参考:
现在我升级到swift3.0,
在哪张图里,
当在 pen/pencil/brush/eraser - 厚度和颜色之间切换时,最后选择的一个将应用于所有。
参考:
还尝试了最新的苹果 pencil API..结果相同
谁能告诉我这个问题的确切解决方案..
啊啊...经过长时间的尝试...找到了解决方案..
就在 CanvasView.swift
上一行override func draw(_ rect: CGRect) {
let context = UIGraphicsGetCurrentContext()!
context.setLineCap(.round)
needsFullRedraw = false //Added this line
if (needsFullRedraw) {
setFrozenImageNeedsUpdate()
frozenContext.clear(bounds)
for array in [finishedLines,lines] {
for line in array {
line.drawCommitedPointsInContext(frozenContext, isDebuggingEnabled: isDebuggingEnabled, usePreciseLocation: usePreciseLocations)
}
}
needsFullRedraw = false
}
frozenImage = frozenImage ?? frozenContext.makeImage()
if let frozenImage = frozenImage {
context.draw(frozenImage, in: bounds)
}
for line in lines {
line.drawInContext(context, isDebuggingEnabled: isDebuggingEnabled, usePreciseLocation: usePreciseLocations)
}
}
或者只是评论下面一行
/*if (needsFullRedraw) {
setFrozenImageNeedsUpdate()
frozenContext.clear(bounds)
for array in [finishedLines,lines] {
for line in array {
line.drawCommitedPointsInContext(frozenContext, isDebuggingEnabled: isDebuggingEnabled, usePreciseLocation: usePreciseLocations)
}
}
needsFullRedraw = false
}*/