ios - iOS 按钮与自定义键盘上的边缘手势冲突
问题描述
我在屏幕左侧和右侧的自定义键盘上有具有 .touchdown 操作的按钮。当我单击它们时,它们不会立即注册 .touchdown 并且似乎在等待查看是否有滑动手势。我尝试使用代码来推迟边缘手势,但在 iOS 13 中,这似乎不起作用。有没有人解决如何让边缘上的按钮在单击时立即执行 .touchdown 动作?
override var preferredScreenEdgesDeferringSystemGestures: UIRectEdge {
return [.left, .bottom, .right]
}
我还尝试在自定义按钮类中使用点函数,但这只会使其突出显示,但仍不能立即执行操作。
override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
let inside = super.point(inside: point, with: event)
if inside && !isHighlighted && event?.type == .touches {
isHighlighted = inside
}
return bounds.insetBy(dx: -2.7, dy: -12).contains(point)
}
解决方案
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
if let window = view.window,
let recognizers = window.gestureRecognizers {
recognizers.forEach { r in
r.delaysTouchesBegan = false
r.cancelsTouchesInView = false
r.isEnabled = false
}
}
}
推荐阅读
- python-3.x - Discord.py - Asyncio 超时无法正常工作
- php - PHP preg_replace 多行指南
- maven - 使用 maven javafx 嵌入 derby db 的 jpa
- php - PHP 创建函数回文
- r - 如何正确使用 lapply 和 Bloomberg Rblpapi 包来提取多组代码
- python - 计算 MNIST 数据库灰度图像的密度
- python - 我需要使用 pyodbc 模块才能连接到 SQL-server 但我不能使用 SQL-SERVER 驱动程序
- c++ - 一个类的实例(不是类本身)可以是另一个类的许多实例的父类吗?
- javascript - 在 JQuery/Javascript 中与 SQLite 数据库交互?
- npm - 使用从 bitbucket 克隆的存储库中的 npm install 时出错?