uber/UberSignature

Weird square at end of drawing

saiedg opened this issue · 5 comments

Does anyone else have this issue of the end of the signature drawing partially cut off? Sometimes it happens, sometimes it doesn't. I'm having a difficult time perfectly reproducing. Hope this can be quickly fixed.

img_3309
img_3310

I'm currently messing around with undo functionality and I am seeing this as well. It's weird, I'll cache the last "signatureImage" each time endContinuousLine is called (so undo just sets the current image to the previous version) But the very last point or two are always left behind. Sometimes they look like the cut off square thing you posted.

I haven't gotten to the bottom of it yet, but I have a hunch it's related. Am really curious to know what the dealio is

It looks like the temporaryBezierPath is the culprit. This was added to give us the ability to single-tap the screen and produce a dot. I completely turned it off and I'm no longer getting the jagged line cap and my undo implementation works as expected. The issue is that I'm no longer getting any line cap at all, or the single dot, since the last couple points after touches end were getting drawn by temporary bezier path.

So, short hacky version, just turn off the temporary bezier path by changing the finalSignatureImage computed property to just return signatureImage instead of returning the signatureImage with the rest of the temporary path. Yeah, it's not ideal, but I haven't messed with the project enough to fix the underlying problem.

Hi! Thank you for getting back to me and I apologize so much for the delayed reply! I still get the box at the end and an additional hitch at the end of the animation if I comment out lines 173 174 175 and 177:
if self.bezierPathLayer.path != output.temporarySignatureBezierPath?.cgPath {
self.bezierPathLayer.path = output.temporarySignatureBezierPath?.cgPath
}
self.isEmpty = self.bezierPathLayer.path == nil && self.imageView.image == nil

Am I doing this incorrectly?

Take a look at UIBezierPath+WeightedPoint.swift in the "line" func.

I was reading it this morning and I think the following:

path.move(to: lines.0.start)
path.addLine(to: lines.1.start)
path.addLine(to: lines.1.end)
path.addLine(to: lines.0.start)

should be changed to:

path.move(to: lines.0.start)
path.addLine(to: lines.1.start)
path.addLine(to: lines.1.end)
path.addLine(to: lines.0.end)

Note the last addLine has changed from adding to start to adding to end.

At least that's what I thought on reading it and I was thinking the bug would manifest as a triangle in the output.

Fixed it!! Thank you!