0
votes

I have a View that contains UIViewRepresentable (some UIView). That UIView has a button as a subView that has its own action. I have 2 problems:

If SwiftUI view has no tap gestures attached, UIView's button event (UIControlEventTouchUpInside) doesn't fire on single tap, instead fires on Long tap only. If SwiftUI view has tap gesture attached, the touch on UIView's button fires fine, but SwiftUI view's event fires also (simultaneous touches) SwiftUI's View's .gesture modifier allows to attach a Gesture with different masks, but they actually take into account only gestures that are attached to SwiftUI Views hierarchy and seems don't take into account gesture attached to it's UIView subviews

VStack(spacing: 0) {
    textfield        <-- UIView inside that has own action
}.onTapGesture {
    endEditing()      <-- this called together with UIView's action
}
1

1 Answers

0
votes

I was having collisions when I touched the swiftUI buttons I put in the UIViewRepresentable. This solution worked for me.

MyUIKitRepresentableView()
    .allowsHitTesting(false)