SwiftUIMidMCQ

When should you use .onTapGesture vs .onSimultaneousGesture in SwiftUI?

Test your knowledge:

Explanation & Code

Use .onTapGesture for standard taps, and .onSimultaneousGesture when you need two gestures to fire together without one cancelling the other.

Use .onTapGesture when:

  • A button-like element (e.g., chat bubble, emoji button)
  • Opening a bottom sheet
  • Selecting an item from a list
  • Toggling a state (expand/collapse)

Use .onSimultaneousGesture when:

  • A scroll view needs a tap gesture (avoid losing scrolling)
  • A draggable view that still detects taps
  • A long press that shouldn't block taps
  • Multi-gesture components (like a map: drag + tap markers)
// Standard tap — cancels scroll gesture
ScrollView {
    Text("Hello")
        .onTapGesture { print("tapped") }  // blocks scroll in some cases
}

// Simultaneous — both gestures fire independently
ScrollView {
    Text("Hello")
        .onSimultaneousGesture(TapGesture().onEnded {
            print("tapped without blocking scroll")
        })
}

Common Misunderstanding:

.onSimultaneousGesture is not a replacement for .onTapGesture.

ModifierPurpose
.onTapGestureDetecting taps — exclusive, can cancel competing gestures
.onSimultaneousGestureCombining gestures without conflict — both fire at once

Use .onTapGesture by default. Only switch to .onSimultaneousGesture when you notice a parent gesture (like ScrollView) is being blocked.

Rate your understanding:

Ready to practice more SwiftUI?

Test yourself with our interactive quiz mode or browse all curated questions for this topic.