O'Reilly logo

iOS Programming: The Big Nerd Ranch Guide by Aaron Hillegass, Christian Keur

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Detecting Taps with UITapGestureRecognizer

The first UIGestureRecognizer subclass you will use is UITapGestureRecognizer. When the user taps the screen twice, all of the lines on the screen will be cleared.

Open TouchTracker.xcodeproj from Chapter 17 and DrawView.swift. Add an init?(coder:) method and instantiate a UITapGestureRecognizer that requires two taps to fire and call the action method on its target.

r​e​q​u​i​r​e​d​ ​i​n​i​t​?​(​c​o​d​e​r​ ​a​D​e​c​o​d​e​r​:​ ​N​S​C​o​d​e​r​)​ ​{​
 ​ ​ ​ ​s​u​p​e​r​.​i​n​i​t​(​c​o​d​e​r​:​ ​a​D​e​c​o​d​e​r​)​

 ​ ​ ​ ​l​e​t​ ​d​o​u​b​l​e​T​a​p​R​e​c​o​g​n​i​z​e​r​ ​=​ ​U​I​T​a​p​G​e​s​t​u​r​e​R​e​c​o​g​n​i​z​e​r​(​t​a​r​g​e​t​:​ ​s​e​l​f​,​
 ​ ​ ​ ​ ​ ​ ​ ​a​c​t​i​o​n​:​ ​"​d​o​u​b​l​e​T​a​p​:​"​) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required