0

I'm trying to make a button that does two different things based on if you tap or if you long press on it. The following code seems like it should work, but only the long press event works. if I just tap it, I see the animation for the button being pressed, but it doesn't do anything until I long press on it.

                Button(action: {}) {
                    Image("no_image_taken")
                        .resizable()
                        .aspectRatio(contentMode: .fit)
                        .cornerRadius(10)
                        .gesture(TapGesture()
                            .onEnded({_ in self.showImagePicker = false}))
                        .gesture(LongPressGesture(minimumDuration: 1)
                            .onEnded({_ in self.showImagePicker = true}))
                }.sheet(isPresented: self.$showImagePicker) {
                    PhotoCaptureView(useExistingPhoto: self.$useExistingPhoto, showImagePicker: self.$showImagePicker, image: self.$optionalImage)
                }

I based my code on the answer given here, but mine still isn't working.

DJFriar
  • 340
  • 7
  • 21

1 Answers1

1

You can just put your gestures actions on Image and there is s no need to be on Button in this purpose.

Mac3n
  • 4,189
  • 3
  • 16
  • 29