Home > Mobile >  SwiftUI - Two Finger Tap gesture
SwiftUI - Two Finger Tap gesture

Time:09-27

Well, I have been looking around google and couldn't manage to find a good way to create an OnTwoFingerTap detection, if anyone could help me out please :) I would be greatful

CodePudding user response:

**So in this link there was a solution, which had errors: Error build: Reference to generic type 'UIViewRepresentableContext' requires

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)
{
}

I fixed it by switchhing UIViewRepresentContext to Context

func makeUIView(context: Context) -> 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: Context)
{
}

CodePudding user response:

Managed to fix it, just changed UIViewRepresentableContext to Context, Seems to be working good, hope it won't destroy stuff :)

  • Related