Search code examples
iosswifttableviewscrollviewgesture

Swift UITableView Swipe During Scroll Animation


I've looked around and tried everything I can think of sort of subclassing TableView, but I think I'm missing something. I have a TableView with entries that I can swipe left and right on, and everything works fine. However, if:

1) I start (vertically) scrolling a little bit, and then swipe, the TableView's superclass, ScrollView, seems to block the swipe from my TableViewCell.

2) I stop scrolling, but the animation hasn't fully stopped, the swipe is still blocked from the TableViewCell.

How can I allow my swipe to get passed through to my TableViewCell, regardless of the vertical scroll?


Solution

  • Swift 2.2, Xcode 7.3

    I fixed this basically by doing what was suggested in this thread: Tell ScrollView to Scroll after other pan gesture

    Below is code that should enable someone else that comes across this thread to scroll in a table view, and be able to swipe, without having to deal with the table view's pan gesture recognizer blocking the swipe due to the mere hint of vertical motion.

    Hope it helps someone.

    So (inside a UITableViewController -- non--essential code emitted):

        var lsgr : UISwipeGestureRecognizer!
    
        override func viewDidLoad(){
            super.viewDidLoad()
            self.lsgr = UISwipeGestureRecognizer(target: self, action: "didSwipeLeft:")
            self.lsgr.direction = .Left
            self.lsgr.cancelsTouchesInView = false
            self.lsgr.delegate = self
        }
    
        func didSwipeLeft(leftSwipe: UISwipeGestureRecognizer){
            var ip = self.tableView.indexPathForRowAtPoint(leftSwipe.locationOfTouch(0,inView: self.tableView))
            print("swipe left - "+String(ip!.row))
        }