Hello Sydney,
Thank you for the response. I forgot to add that there is a metal view involved in this app and that could be another reason why this problem occurs. I have some simple code here that shows the problem. Can you give this a test? You will notice that the gesture only gets recognized about half the time.
struct ContentView: View {
var body: some View {
MetalView()
}
}
struct MetalView: UIViewRepresentable {
var device: MTLDevice?
init() {
self.device = MTLCreateSystemDefaultDevice()
}
func makeUIView(context: Context) -> MTKView {
let mtkView = MTKView()
mtkView.device = device
mtkView.clearColor = MTLClearColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0)
mtkView.delegate = context.coordinator
// Add tap gesture recognizer
let tapGesture = UITapGestureRecognizer(target: context.coordinator, action: #selector(context.coordinator.handleTap(_:)))
tapGesture.numberOfTapsRequired = 1
// Should require both hands to tap.
tapGesture.numberOfTouchesRequired = 2
mtkView.addGestureRecognizer(tapGesture)
return mtkView
}
func updateUIView(_ uiView: MTKView, context: Context) { }
func makeCoordinator() -> Coordinator {
Coordinator(self)
}
class Coordinator: NSObject, MTKViewDelegate {
var parent: MetalView
init(_ parent: MetalView) {
self.parent = parent
}
func mtkView(_ view: MTKView, drawableSizeWillChange size: CGSize) { }
func draw(in view: MTKView) {
guard let drawable = view.currentDrawable else { return }
guard let descriptor = view.currentRenderPassDescriptor else { return }
let commandQueue = parent.device?.makeCommandQueue()
let commandBuffer = commandQueue?.makeCommandBuffer()
let renderEncoder = commandBuffer?.makeRenderCommandEncoder(descriptor: descriptor)
renderEncoder?.endEncoding()
commandBuffer?.present(drawable)
commandBuffer?.commit()
}
@objc func handleTap(_ sender: UITapGestureRecognizer) {
print("MTKView tapped")
}
}
}
I'm happy to submit a feedback report but I'm curious what your feedback is when you see the issue.
Thank you!