嘿,我在使用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!)
}
}
答案 0 :(得分:0)
嘿,您需要检查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!)
}
}
}