How to do it...

  1. Create a new Xcode project called Gestures with Single View template.
  2. Open the storyboard, and in the single view controller, change its size to iPhone 4-inch size.
  3. Drag a UIView to the center of the screen and set its frame to (X = 127, Y = 259, Width = 120, Height = 80).
  4. Change its color to any color you want instead of white.
  5. Link it to ViewController.swift via IBOutlet and call it sampleView:
  1. Now, open the ViewController.swift file, and let's add the following code to set up the UITapGestureRecognizer:
      // MARK: - Tap Gesture -           func setupTapGesture(){  let tapGesture = UITapGestureRecognizer(target: self, action: ...

Get iOS Programming Cookbook 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.