I am trying to add UILongGestureRecognizer to my Custom CollectionView Cell but handler function never called. This is my gesture
and handlerFunc
from custom cell:
let longPress = UILongPressGestureRecognizer(target: self, action: #selector(handleLongPress(_:)))
@objc func handleLongPress(_ recognizer: UILongPressGestureRecognizer) {
switch recognizer.state {
case .possible:
break
case .began:
print("began")
break
case .changed:
break
case .ended:
print("ended")
break
case .cancelled:
break
case .failed:
break
@unknown default:
break
}
}
Also, this is my cell configure
function:
func configure(with viewModel: RecordsCollectionViewCellViewModel, itemCount: Int) {
longPress.numberOfTapsRequired = 1
longPress.minimumPressDuration = 0.3
longPress.delaysTouchesBegan = true
longPress.delegate = self
self.bringSubviewToFront(gestureView)
gestureView.isUserInteractionEnabled = true
gestureView.addGestureRecognizer(longPress)
}
The gestureView
is the transparent view at the top of the cell.