user12232037
user12232037

Reputation:

SwiftUI - Add two gestures to a view?

I want to add two gesture recongnisers to a view, but I'm unsure how to do it! I've tried the below, but only the first one fires (whatever order they are in).

            .gesture(
            TapGesture(count: 2)
                .onEnded { _ in
                     print("Double Tap!")
                }
        )
        .gesture(
            LongPressGesture()
                .onEnded { _ in
                    print("Long Press!")
            }
        )

I thing I need to use simultaneousGesture, but I'm unsure of the syntax. I've tried:

.simultaneousGesture(LongPressGesture().onEnded({self.showAddEditToDoView.toggle()}), TapGesture().onEnded({print("Double Tap!")}))

But that produces:

Missing argument label 'including:' in call

Any help much appreciated.

Upvotes: 5

Views: 4757

Answers (1)

Sorin Lica
Sorin Lica

Reputation: 7636

try

.simultaneousGesture(LongPressGesture().onEnded({ _ in 
   self.showAddEditToDoView.toggle()
}))
.simultaneousGesture(TapGesture().onEnded({
   print("Double Tap!")
}))

Upvotes: 8

Related Questions