swiftui - 如何使用 SwiftUI 禁用整个应用程序或仅视图的多点触控?
解决方案
没有 SwiftUI 解决方案,但您可以在 SwiftUI 应用程序中使用 UIKit 解决方案。
使用UIView.appearance()
. 这将禁用整个应用程序的多点触控。
@main
struct SwiftUIDEMO: App {
init() {
UIView.appearance().isMultipleTouchEnabled = false
UIView.appearance().isExclusiveTouch = true
}
// Body View
}
或者你也可以使用UIViewController
touch event 和 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
}
}
推荐阅读
- javascript - 尝试创建队列时出现 ChromeCast session_error
- kubernetes - 将 pod 分配给工作人员,而不使用 nodeSelector 等特定于部署的内容。安全约束
- enterprise-architect - Enterprise Architect - SysML 图表标题
- python - Python Matplotlib Circle 问题
- sql - 改进包含多个子查询的 SQL 查询
- android - 无法完成会话:INSTALL_FAILED_NO_MATCHING_ABIS:无法提取本机库,res=-113
- database-backups - MS SQL 2017 Express:还原备份时出现奇怪错误
- python - 如何检查任意类实例是否存在并从另一个模块调用其方法?
- github - npm 安装一个分叉的分支
- regex - Angular 5 表单自定义验证无法正常工作