UILongPressGestureRecognizer

Let’s test out two other subclasses of UIGestureRecognizer: UILongPressGestureRecognizer and UIPanGestureRecognizer. When the user holds down on a line (a long press), that line should be selected. While a line is selected in this way, the user should be able to drag the line (a pan) to a new position.

In this section, we’ll focus on the long press recognizer. In TouchDrawView.m, instantiate a UILongPressGestureRecognizer in initWithFrame: and add it to the TouchDrawView.

[​s​e​l​f​ ​a​d​d​G​e​s​t​u​r​e​R​e​c​o​g​n​i​z​e​r​:​t​a​p​R​e​c​o​g​n​i​z​e​r​]​;​
 U​I​L​o​n​g​P​r​e​s​s​G​e​s​t​u​r​e​R​e​c​o​g​n​i​z​e​r​ ​*​p​r​e​s​s​R​e​c​o​g​n​i​z​e​r​ ​=​ ​ ​ ​ ​[​[​U​I​L​o​n​g​P​r​e​s​s​G​e​s​t​u​r​e​R​e​c​o​g​n​i​z​e​r​ ...

Get iOS Programming: The Big Nerd Ranch Guide 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.