SwiftUI Tutorial - How to implement the Swiping Motion with SwiftUI - Part 13

Опубликовано: 29 Сентябрь 2024
на канале: Credo Academy
1,346
19

🟢 LIMITED TIME OFFER - SAVE 37%
Practical iOS and macOS app development tutorials with SwiftUI in 4K
https://credo.academy

How to implement the Swiping Motion with SwiftUI? We’re going to implement the swipe feature first before we dynamically remove and create new cards. Yet again, this is a fairly advanced topic, so if you haven’t worked with gestures intensively using SwiftUI then I highly recommend you to watch the section about the basics of gestures in the course.

First, we define the possible states of the drag gesture. To represent the drag states we use a new enum.

This Drag State defines and represents all of the stages for our custom swipe gesture.

As you can see, basically, we have 3 stages of this drag gesture:

• The first state is for when no gesture happens. This is the inactive state.
• The second one is when a user taps on the screen. This is the pressing state.
• The last one is when the actual drag gesture is happening.

After the states enum creation, let's define a new @GestureState variable to store the drag state we discussed before.

#SwiftUI #Xcode #iOSDevelopment