ios - 如果将交互添加到长按功能而不是覆盖功能,您如何调用 addGestureRecognizer?
问题描述
为什么 add 交互需要在 objC func 中?
因为只有在满足某些数据库检查时才应该添加它。
如果将交互添加到覆盖功能,它是如何成功工作的。addGestureRecognizer 也被添加在那里。
var cc: UIContextMenuInteraction!
override func viewDidLoad() {
super.viewDidLoad()
like?.isUserInteractionEnabled = true
self.cc = UIContextMenuInteraction(delegate: self)
like.addInteraction(cc)
let longPress = UILongPressGestureRecognizer(target: self, action: #selector(didLongPress))
like?.addGestureRecognizer(longPress)
}
@objc func didLongPress() {
////whatever goes
}
但是,如果将交互添加到 objC 函数而不是覆盖函数,则它仅适用于第 2 次及以后的长按。这大概是因为第一次长按只启用交互。
verride func viewDidLoad() {
super.viewDidLoad()
like?.isUserInteractionEnabled = true
let longPress = UILongPressGestureRecognizer(target: self, action: #selector(didLongPress))
like?.addGestureRecognizer(longPress)
}
@objc func didLongPress() {
if statement{
cc = UIContextMenuInteraction(delegate: self)
like.addInteraction(cc)
}
}
解决方案
推荐阅读
- c# - 使用 Dynamic Linq 的具有多个条件的左外连接
- python - Python绘制多维列表?
- sql-server - 如何代表远程服务器执行 sys.dm_exec_connections?
- html - 在网格内容上强制滚动条
- ios - 线程 1:在 iPhone Swift 4.1 上运行时发出信号 SIGABRT;0_abort_with_payload
- javascript - html 表单数据到 MySQL db
- c++ - 如何在 QML 文档中嵌入 QLabel?
- php - 当:HTML Input type =“text”时如何防止数字数据?
- git - Git reset 显示要从服务器获取的一项
- php - 关于如何清理/缩短我的代码的任何建议?