How to draw emojis on UIImageView using gesture

205 Views Asked by At

Hope all are safe in this pandemic situation.

I have been trying to design an application similar to SnapChat, I am stucked in an issue since a week for which I am not getting any library from gitHub or any code reference from stackOverFlow. I have to draw various emoji lines using swipe gesture on an UIImageView for which I have used UIGraphicsGetCurrentContext() The issue I am facing is to managing equal space between the emojis. I am attaching the screenshot of my work done till now. Any help would be appreciated. Thanks in advance

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

enter image description here

1

There are 1 best solutions below

0
On

I assume you are using a pan gesture recognizer rather than a swipe gesture recognizer?

You need to write code that takes the points you receive from the gesture recognizer and treat them as the endpoints of a line segment. You would then apply your emoji evenly along the space between the points at a regular interval.

If you want more detailed help than that you will need to post your current drawing code.