- Create a new Xcode project called Gestures with Single View template.
- Open the storyboard, and in the single view controller, change its size to iPhone 4-inch size.
- Drag a UIView to the center of the screen and set its frame to (X = 127, Y = 259, Width = 120, Height = 80).
- Change its color to any color you want instead of white.
- Link it to ViewController.swift via IBOutlet and call it sampleView:
- 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: ...