Gestures
Swipe, tap and drag with SwiftUI
Gestures
Swipe, tap and drag with SwiftUI
0
0
Checkbox to mark video as read
Mark as read

Gestures are an essential part of creating interactive and engaging user interfaces in iOS. SwiftUI provides a powerful, declarative approach to handling common gestures like taps, long presses, swipes, and drags. In this article, we’ll cover how to add each of these gestures to your SwiftUI views.

Tap Gesture

The tap gesture is the simplest and most commonly used gesture, often used for triggering actions with a single tap on a view. To use a tap gesture, apply the .onTapGesture modifier to the view:

import SwiftUI

struct ContentView: View {
    @State private var isTapped = false

    var body: some View {
        Circle()
            .fill(isTapped ? Color.green : Color.blue)
            .frame(width: 100, height: 100)
            .onTapGesture {
                isTapped.toggle()
            }
    }
}

Long Press Gesture

Continue reading

Access to all the content with our plans.

Basic Plan

FREE

Start Now
  • Junior level content
  • Senior level content
  • Expert level content
  • Extra content
  • Question submissions
Monthly
Yearly

Plan logo

-

Unlimited access to the whole content

  • Junior level content
  • Senior level content
  • Expert level content
  • Extra content
  • Question submissions

Stripe secure payment methods
Plan logo

-

Unlimited access to the whole content

  • Junior level content
  • Senior level content
  • Expert level content
  • Extra content
  • Question submissions

Stripe secure payment methods
Plan logo

-

Solve your doubts at any level

  • Junior level content
  • Senior level content
  • Expert level content
  • Extra content
  • 2 Question submissions per week

Stripe secure payment methods
Plan logo

-

Solve your doubts at any level

  • Junior level content
  • Senior level content
  • Expert level content
  • Extra content
  • 2 Question submissions per week

Stripe secure payment methods

0 Comments

Join the community to comment
Sign Up
I have an account
Be the first to comment

Accept Cookies

We use cookies to collect and analyze information on site performance and usage, in order to provide you with better service.

Check our Privacy Policy