scrollEnabled内部外部UIScrollView的scrollViewDidScroll需要两次刷卡

问题描述:

我有UICollectionView里面UITableViewCell。我想要启用或禁用基于两者的contentOffset的滚动UICollectionViewUITableView。例如,在UICollectionView的ViewController中,我有一个代码 -scrollEnabled内部外部UIScrollView的scrollViewDidScroll需要两次刷卡

- (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]; 
    } 

} 

但启用滚动不会立即生效。第一次滚动不启用或禁用_collectionView但在第二次滚动它按预期工作。我们不能在动态中启用滚动(仅在一次滑动/滚动中)?

scrollViewDidScroll来回调用收集视图的弹跳动画。出于这个原因,一旦它的动画设置scrollEnabled = true后其设置scrollEnabled = false。 尝试检查范围如0到10或某个阈值。

或者你可以试试这个:

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

    } else { 
     _collectionView.scrollEnabled = true; 

    } 

} 
+0

感谢您的答案,但它不会因为阈值。 _collectionView.scrollEnabled = true/false即时调用,但为了看到我需要结束滚动并再次滚动的效果。这一次它将按预期工作。 – Vashum