2

I wanna disable multi touch in swiftUI but I don't find any solution Is there any way to do this???

everything I found are related to UIKit :

How to disable multitouch?

fdvfarzin
  • 1,107
  • 1
  • 4
  • 14

1 Answers1

1

No SwiftUI solution but you can use UIKit solution in SwiftUI app.

Use UIView.appearance(). This will disable multi-touch on the whole app.

@main
struct SwiftUIDEMO: App {
    init() {
        UIView.appearance().isMultipleTouchEnabled = false
        UIView.appearance().isExclusiveTouch = true
    }
    
    // Body View
}

Or you can also use UIViewController touch event and maange .isUserInteractionEnabled.

extension UIViewController {
    open override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
        super.touchesMoved(touches, with: event)
        self.view.isUserInteractionEnabled = true
    }
    open override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
        super.touchesEnded(touches, with: event)
        self.view.isUserInteractionEnabled = true
    }
    open override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
        super.touchesEnded(touches, with: event)
        self.view.isUserInteractionEnabled = true
    }
}
Raja Kishan
  • 16,767
  • 2
  • 26
  • 52
  • If you’re using first code init then you can write this init code to your SwiftUI view and for second approach just make a one file and place the code – Raja Kishan May 09 '21 at 17:04
  • Your solution is wright tnx but I understand my problem is something else I should disable multi drag gesture not touch – fdvfarzin May 09 '21 at 17:15
  • 1
    This not worked for me. Don't know why. SwiftUI – Binh Ho May 11 '22 at 07:14