如何在整个应用程序上禁用多点触控或仅使用 SwiftUI 的视图? [英] How to disable multi touch on entire app or just a view using SwiftUI?

查看:29
本文介绍了如何在整个应用程序上禁用多点触控或仅使用 SwiftUI 的视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 swiftUI 中禁用多点触控,但我没有找到任何解决方案有没有办法做到这一点???

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

我发现的一切都与 UIKit 相关:

everything I found are related to UIKit :

如何禁用多点触控?

推荐答案

没有 SwiftUI 解决方案,但您可以在 SwiftUI 应用中使用 UIKit 解决方案.

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

使用UIView.appearance().这将在整个应用上禁用多点触控.

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
}

或者你也可以使用 UIViewController 触摸事件和 maange .isUserInteractionEnabled.

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

这篇关于如何在整个应用程序上禁用多点触控或仅使用 SwiftUI 的视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆