0
votes

I have UICollectionView carousel with UITableView nested inside each UICollectionViewCell. UICollectionView's layout.scrollDirection = .horizontal, so

  1. UITableView scroll up/down works fine
  2. UITableViewCell swipe does not work, but UICollectionView scrolling is triggered instead.

How to keep collectionView.isScrollEnabled true, but prioritise UITableViewCell to allow deleting when swiping on it?

1

1 Answers

0
votes

I've tried gestureRecognizerShouldBegin and it did the job. Here is my solution (zoomed it indicates if collectionView is fullscreen or not). The logic is to check if gesture start point is inside any of tableView rows ( with small gap on left/right to keep ability of collectionView scroll when pan from the sides using insetBy(dx:dy:) ), currentCell is parent UICollectionViewCell.

extension MyCollectionView: UIGestureRecognizerDelegate {  

    override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {  
        guard zoomed, let currentCell = currentCell, gestureRecognizer.view is MyCollectionView else { return true }  
        let cellViews = currentCell.myTableView.visibleCells  
        let touchPoint = gestureRecognizer.location(in: currentCell.myTableView)  
        let cellsAtPoint = cellViews.filter {  
            let localPoint = $0.convert(touchPoint, from: currentCell.myTableView)  
            return $0.bounds.insetBy(dx: 40, dy: 0).contains(localPoint)  
        }  
        return cellsAtPoint.count == 0  
    }  

}