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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.