| name | swiftui-gestures |
| description | Implementing touch interactions, gestures, and haptic feedback in SwiftUI for responsive user experiences |
| tags | ["swift","swiftui","gestures","touch","haptics","interactions"] |
SwiftUI Gestures & Interactions
Purpose
Implementing touch interactions, gestures, and haptic feedback in SwiftUI for engaging, responsive user experiences.
Basic Gestures
Tap Gesture
Text("Tap me")
.onTapGesture {
print("Tapped!")
}
Image("photo")
.onTapGesture(count: 2) {
toggleZoom()
}
Color.blue
.frame(width: 200, height: 200)
.onTapGesture { location in
print("Tapped at: \(location)")
}
Long Press
struct LongPressButton: View {
@State private isPressed
body: {
()
.fill(isPressed .red : .blue)
.frame(width: , height: )
.onLongPressGesture(minimumDuration: ) {
performAction()
} onPressingChanged: { pressing
withAnimation(.easeInOut(duration: )) {
isPressed pressing
}
}
}
}