My case was: collectionView inside a View
I was trying to add the gestureRecognizer in a config()
method that I have wrote by myself.
After some workaround i've found that
I have simply to move the code inside the awakeFromNib()
.
override func awakeFromNib() {
//other code
let longPressGesture = UILongPressGestureRecognizer(target: self, action: #selector(handleLongGesture(gesture:)))
self.collectionView.addGestureRecognizer(longPressGesture)
}
And it worked well.
I hope that this can help someone.