I'm having trouble adding a long press gesture to my UITableView. Well, technically, I do have a long press gesture recognizer, but I set the minimum taps duration to 0.08. I did this because I want to have the same general action for tapping and holding down a cell, but the action only changes based on how long the cell was held. Anyway, here is the code where I add the gesture recognizer (in viewDidLoad
) :
var longPress:UILongPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: "handleLongPress:")
longPress.minimumPressDuration = 0.08
longPress.delegate = self
longPress.cancelsTouchesInView = false
self.tableView.addGestureRecognizer(longPress)
self.tableView.panGestureRecognizer.requireGestureRecognizerToFail(longPress)
In my handleLongPress()
function, I get the CGPoint where there was a long press and then get the tableView cell from that.
So basically, if I scroll quickly, (like if I flick the screen), the table view scrolls fine. If I try to scroll slowly, the long press event fires and I can't scroll.
All I want to do is to be able to scroll slowly, I want the tableviews default scroll gesture to override any long press.
Thanks!
ScrollViews have a panGestureRecognizer
property, you can call requireGestureRecognizerToFail
on your long press recognizer with the scrollView's panGestureRecognizer as an argument and it will only fire if the pan gesture in the scroll view fails.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With