首页 > 解决方案 > 单击并拖动 CGContext 绘图以将其放置在屏幕上的任何位置

问题描述

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()

我正在使用上面的代码在图像上徒手绘制。绘制图像后,可以单击绘图上的任意位置并将其移动以将其放置在屏幕上的任意位置。

标签: iosswiftcore-graphics

解决方案


检查这个库:https ://github.com/luiyezheng/JLStickerTextView 我认为这就是我想要的。


推荐阅读