History
Loading...
Loading...
October 3, 2025
simultaneousGesture() instead of gesture() when you need multiple gestures to work together. Unlike gesture() which replaces existing gestures, simultaneousGesture() allows tap, drag, and other gestures to coexist on the same view.This approach allows multiple gestures to work simultaneously on the same view by using `simultaneousGesture()` for each interaction type. Each gesture maintains its own state and responds independently, creating rich multi-touch interactions.
struct InteractiveCard: View {
@State private var offset = CGSize.zero
@State private var scale: CGFloat = 1.0
@State private var tapCount = 0
var body: some View {
RoundedRectangle(cornerRadius: 12)
.fill(.blue.gradient)
.frame(width: 200, height: 150)
.scaleEffect(scale)
.offset(offset)
.overlay(Text("Taps: \(tapCount)"))
.simultaneousGesture(
TapGesture()
.onEnded { tapCount += 1 }
)
.simultaneousGesture(
DragGesture()
.onChanged { offset = $0.translation }
.onEnded { _ in offset = .zero }
)
.simultaneousGesture(
MagnificationGesture()
.onChanged { scale = $0 }
.onEnded { _ in scale = 1.0 }
)
}
}Complex UI elements often need multiple interaction patterns. Using simultaneous gestures prevents gesture conflicts and provides users with intuitive multi-touch capabilities, especially important for interactive content like image viewers, drawing apps, or gaming interfaces.