Post marked as solved
Click to stop watching this thread.
You have stopped watching this post. Click to start watching again.
contentPostList.repliessolved.tooltip
Replied In
Two finger tap gesture in SwiftUI
Thanks Claude,I hope the next version of SwiftUI will handle this better.This is my code:struct ContentView: View {
var body: some View {
Rectangle()
.fill(Color.black)
.frame(width: 200, height: 200)
.overlay(
TappableView { gesture in
print("2 touches detected")
})
}
}import SwiftUI
struct TappableView: UIViewRepresentable
{
var tapCallback: (UITapGestureRecognizer) -> Void
typealias UIViewType = UIView
func makeCoordinator() -> TappableView.Coordinator
{
Coordinator(tapCallback: self.tapCallback)
}
func makeUIView(context: UIViewRepresentableContext) -> UIView
{
let view = UIView()
let doubleTapGestureRecognizer = UITapGestureRecognizer(target: context.coordinator, action: #selector(Coordinator.handleTap(sender:)))
/// Set number of touches.
doubleTapGestureRecognizer.numberOfTouchesRequired = 2
view.addGestureRecognizer(doubleTapGestureRecognizer)
return view
}
func updateUIView(_ uiView: UIView, context: UIViewRepresentableContext)
{
}
class Coordinator
{
var tapCallback: (UITapGestureRecognizer) -> Void
init(tapCallback: @escaping (UITapGestureRecognizer) -> Void)
{
self.tapCallback = tapCallback
}
@objc func handleTap(sender: UITapGestureRecognizer)
{
self.tapCallback(sender)
}
}
}