More Gesture Recognizers

In this section, you are going to add the ability for a user to select a line by pressing and holding (a long press) and then move the selected line by dragging the finger (a pan). This will require two more subclasses of UIGestureRecognizer: UILongPressGestureRecognizer and UIPanGestureRecognizer.

UILongPressGestureRecognizer

In DrawView.swift, instantiate a UILongPressGestureRecognizer in init?(coder:) and add it to the DrawView.

    ...
    addGestureRecognizer(tapRecognizer)

    let longPressRecognizer = UILongPressGestureRecognizer(target: self,
            action: #selector(DrawView.longPress(_:)))
    addGestureRecognizer(longPressRecognizer)
}

Now when the user holds down on the DrawView, the method longPress(_:) ...

Get iOS Programming: The Big Nerd Ranch Guide, 6th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.