希望大家在这次疫情中都平安。
我一直在尝试设计一个类似于 SnapChat 的应用程序,自从一周以来我一直陷入一个问题,我没有从 gitHub 获得任何库或从 stackOverFlow 获得任何代码参考。我必须在使用UIGraphicsGetCurrentContext()的 UIImageView 上使用滑动手势绘制各种表情符号线 我面临的问题是管理表情符号之间的相等空间。我附上我到目前为止完成的工作的屏幕截图。任何帮助,将不胜感激。提前致谢
func drawLineFrom(_ fromPoint: CGPoint, toPoint: CGPoint) {
// isDrawingEmoji is used as a boolean to manage simple line drawing or emoji drawing.
if isDrawingEmoji == true {
UIGraphicsBeginImageContext(topImageView.frame.size)
let context = UIGraphicsGetCurrentContext()
context?.setAlpha(1.0)
topImageView.image?.draw(in: self.img.frame)
if let emoji = selectedEmoji.cgImage {
context?.draw(emoji , in: CGRect(x: toPoint.x , y: toPoint.y, width: 50, height: 50))
}
topImageView.clipsToBounds = true
topImageView.image = UIGraphicsGetImageFromCurrentImageContext()
topImageView.alpha = 1.0
UIGraphicsEndImageContext()
}