如何解决如果将交互添加到长按功能而不是覆盖功能,您如何调用 addGestureRecognizer?
为什么添加交互需要在 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)
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。