0

I have UICollectionView inside UITableViewCell. I wanted to enable or disable scrolling of UICollectionView and UITableView based on contentOffset of both. For example, inside UICollectionView's ViewController I have a code -

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if (scrollView.contentOffset.y == 0) {
        _collectionView.scrollEnabled = false;
        // This will enable _tableView scroll which is implemented in UITableView's ViewController
        [_delegate toggleScroll:true];

    } else {
        _collectionView.scrollEnabled = true;
       // This will disable _tableView scroll which is implemented in UITableView's ViewController
        [_delegate toggleScroll:false];
    }

}

But enabling the scroll does not effect immediately. First scroll does not enable or disable _collectionView but on second scroll it works as expected. Can't we enable the scroll on the fly(Only on one swipe/scroll)?

Vashum
  • 853
  • 1
  • 10
  • 24

1 Answers1

0

scrollViewDidScroll get called back and forth for bouncing animation of collection view. For that reason once its setting scrollEnabled = false after animation its setting scrollEnabled = true. Try to check in a range like 0 to 10 or some threshold value.

Or you can try this:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if (scrollView.contentOffset.y <= 10) {
        _collectionView.scrollEnabled = false;

    } else {
        _collectionView.scrollEnabled = true;

    }

}
Torongo
  • 1,021
  • 1
  • 7
  • 14
  • thanks for your answer but its not because of the threshold value. _collectionView.scrollEnabled = true/false is call instantly but in order to see the effect I need to end the scroll and scroll again. This time it will work as expected. – Vashum Aug 19 '17 at 12:50