Skip to content

SwiftUI: Tap Gesture

With tap gesture, you may specify what would be the action with each tap. In addition to that, you may even adjust the tap frequency. For example, you can adjust the tap frequency to 2 where a user will have to tap twice for an action to take place.

A gesture that recognizes one or more taps.

Apple Documentation

In this tutorial, you’ll learn what is Tap Gesture in SwiftUI. You’ll learn:

  • How to use Tap Gesture.

Prerequisites

To follow along this tutorial, you’ll need some basic knowledge in:

  • A basic familiarity with Swift.
  • At least Xcode 11

Tap Gesture

Imagine how cool would that be if you are able to control the day with a tap. Thanos can snap his finger but you can tap your finger. With a tap of a finger, day time will turn to night time and vice versa. Now that is some next level Thanos.

As always, you will need a State to hold a value.

With the value, you will then decide what to show. If isDay is true, you will show a sun. You can tweak the tap gesture count accordingly but here, it is being set at 2.

As a result, you are now more powerful than Thanos.

Where to go From Here

If you feel like you are ready to take on more challenges, feel free to check out some other tutorials that we have created:

Published inSwiftUI

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *