3

I am making use of swift 2.3 with TouchCanvas (Apple Pencil Sample App),

in which while drawing,

I am able to switch between pen/pencil/brush/eraser - thickness & colors and the same is applied correspondingly.

Ref: Screen1_Swift2.3_vs_Swift3.0.png

Now I upgraded to swift 3.0,

in which which drawing,

when switch between pen/pencil/brush/eraser - thickness & colors, the last picked one is applied to ALL.

Ref:Screen2_Swift2.3_vs_Swift3.0.png

and also tried apple latest pencil API..Results were same

can please any one tell me exact solution for this..

abdul sathar
  • 2,395
  • 2
  • 28
  • 38

1 Answers1

2

Ahhhh...After trying long hours ...found an solution..

Just one line on CanvasView.swift

override func draw(_ rect: CGRect) {
        let context = UIGraphicsGetCurrentContext()!

        context.setLineCap(.round)

needsFullRedraw = false //Added this line

        if (needsFullRedraw) {
            setFrozenImageNeedsUpdate()
            frozenContext.clear(bounds)
           for array in [finishedLines,lines] {
                for line in array {
                    line.drawCommitedPointsInContext(frozenContext, isDebuggingEnabled: isDebuggingEnabled, usePreciseLocation: usePreciseLocations)

                }

            }
            needsFullRedraw = false
        }

        frozenImage = frozenImage ?? frozenContext.makeImage()

        if let frozenImage = frozenImage {
            context.draw(frozenImage, in: bounds)
        }

     for line in lines {
            line.drawInContext(context, isDebuggingEnabled: isDebuggingEnabled, usePreciseLocation: usePreciseLocations)

        }

    }

or just commented the following line

/*if (needsFullRedraw) {
                setFrozenImageNeedsUpdate()
                frozenContext.clear(bounds)
               for array in [finishedLines,lines] {
                    for line in array {
                        line.drawCommitedPointsInContext(frozenContext, isDebuggingEnabled: isDebuggingEnabled, usePreciseLocation: usePreciseLocations)

                    }

                }
                needsFullRedraw = false
            }*/
abdul sathar
  • 2,395
  • 2
  • 28
  • 38