UIGraphicsBeginImageContext(MyImage.frame.size)
let context = UIGraphicsGetCurrentContext()
tempImage.image?.draw(in: CGRect(x: 0, y: 0, width: MyImage.frame.size.width, height: MyImage.frame.size.height))
context?.move(to: startPoint)
context?.addLine(to: point)
context?.setLineCap(.round)
context?.setLineWidth(3)
context?.setStrokeColor(UIColor.blue.cgColor)
context?.setBlendMode(.normal)
context?.strokePath()
tempImage.image = UIGraphicsGetImageFromCurrentImageContext()
tempImage.alpha = 1.0
UIGraphicsEndImageContext()
我使用上面的代码在图像上绘制徒手画。绘制图像后,可以单击图形上的任意位置并移动它以将其放置在屏幕上的任何位置。