gpt4 book ai didi

ios - 长按手势多次调用

转载 作者:行者123 更新时间:2023-12-04 00:30:29 27 4
gpt4 key购买 nike

我遇到了 UILongPressGestureRecognizer 的问题,我使用了以下代码:-

func addLongPressGesture(){
let lngPr = UILongPressGestureRecognizer.init(target: self, action: #selector(self.handleLongPress(gesture:)))
lngPr.delaysTouchesEnded = true
self.addGestureRecognizer(lngPr)
}
@objc func handleLongPress(gesture:UIGestureRecognizer){

if selectedIndexPath != nil && delegate != nil{
self.delegate?.delegateLongPressed(atIndexPath: selectedIndexPath!)
}
}

最佳答案

你需要检查 UILongPressGesture 的状态来修改你的函数试试这个:-

func addLongPressGesture(){
let lngPr = UILongPressGestureRecognizer.init(target: self, action: #selector(self.handleLongPress(gesture:)))
lngPr.delaysTouchesEnded = true
self.addGestureRecognizer(lngPr)
}
@objc func handleLongPress(gesture:UIGestureRecognizer){
if gesture.state == .ended{
if selectedIndexPath != nil && delegate != nil{
self.delegate?.delegateLongPressed(atIndexPath: selectedIndexPath!)
}
}
}

关于ios - 长按手势多次调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51762574/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com