如果我尝试在canvasImageView框架之外绘制,则正在绘制线条,但如果我触摸canvasImageView的中间,则它根本不起作用。我有层次结构mainView,然后是view,然后是scrollview,然后是canvasView,然后是imageView,然后是canvasImageView来绘制线条
fileprivate func drwaagain(lineappend : [[CGPoint]]) {
// 1
let canvasSize = canvasImageView.frame.size
UIGraphicsBeginImageContextWithOptions(canvasSize, false, 0)
if let context = UIGraphicsGetCurrentContext() {
canvasImageView.image?.draw(in: CGRect(x: 0, y: 0, width: canvasSize.width, height: canvasSize.height))
if(isDrawing)
{
lineappend.forEach { (lineappend) in
for (i, p) in lineappend.enumerated() {
if i == 0 {
context.move(to: p)
} else {
context.addLine(to: p)
}
}
}
}
else
{
lineremove.forEach { (lineremove) in
for (i, p) in lineremove.enumerated() {
if i == 0 {
context.move(to: p)
} else {
context.addLine(to: p)
}
}
}
}
// 3
context.setLineCap( CGLineCap.round)
context.setLineWidth(3.0)
if(isDrawing)
{
context.setStrokeColor(drawColor.cgColor)
context.setBlendMode( CGBlendMode.normal)
}
else
{
context.setBlendMode(CGBlendMode.clear)
}
context.strokePath()
canvasImageView.image = UIGraphicsGetImageFromCurrentImageContext()
}
UIGraphicsEndImageContext()
}
最佳答案
当我执行绘图时,我禁用了 ScrollView super View 的用户交互,并在完成绘图后再次启用它。
关于ios - 在canvasImageView上绘图无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59284772/