Skip to content

continue line #42

@dcooley

Description

@dcooley

I've updated the touchesBegan function in my forked repo to experiment adding a 'continue path' functionality, where the line you draw will automatically continue from the last one you did (if it exists)

continuousLine

Is something like this worth adding into the library?


The updated touchesBegan() looks like

    /// Determines whether the path should continue from the last touch point.
    public var shouldContinuePath = false


    override open func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        guard isEnabled, let touch = touches.first else { return }
        if #available(iOS 9.1, *) {
            guard allowedTouchTypes.flatMap({ $0.uiTouchTypes }).contains(touch.type) else { return }
        }
        guard delegate?.swiftyDraw(shouldBeginDrawingIn: self, using: touch) ?? true else { return }
        delegate?.swiftyDraw(didBeginDrawingIn: self, using: touch)
        
        firstPoint = shouldContinuePath && previousPoint != .zero ? previousPoint : touch.location(in: self)
        setTouchPoints(touch, view: self)
          
        let newLine = DrawItem(path: CGMutablePath(),
                           brush: Brush(color: brush.color.uiColor, width: brush.width, opacity: brush.opacity, blendMode: brush.blendMode), isFillPath: false)
        if shouldContinuePath && currentPoint != .zero {
            // draw a straight line between the end of the last touch point
            // and this new touch point
            newLine.path.addPath(createNewStraightPath())
        }
        addLine(newLine)
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions