0

有这个错误,当我拖UICollectionViewCell集合的框架之外发生的事情:集合的contentOffset被重置为0,我想滚动到顶部,在拖动单元格,即使低于集合。问题是contentOffset必须手动放回到它原来所在之处而这在视觉延迟。拖动单元格改变其contentOffset

我试图锁定滚动的同时拖动,如以下

- (void)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout willBeginDraggingItemAtIndexPath:(NSIndexPath *)indexPath { 
    collectionView.scrollEnabled = NO; 
} 

- (void)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout didEndDraggingItemAtIndexPath:(NSIndexPath *)indexPath { 
    collectionView.scrollEnabled = YES; 
} 

,并没有做任何事情,contentOffset仍然改变。还做了以下

- (CGPoint)collectionView:(UICollectionView *)collectionView targetContentOffsetForProposedContentOffset:(CGPoint)proposedContentOffset { 

    if (proposedContentOffset.y > -10.0f) { // Minimum scroll from top is -10 
     return CGPointMake(proposedContentOffset.x, -10.0f); 
    } 
    return proposedContentOffset; 
} 

- (void)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout willEndDraggingItemAtIndexPath:(NSIndexPath *)indexPath { 

    if (collectionView.contentOffset.y > -10.0f) { // Minimum scroll from top is -10 
     [collectionView setContentOffset:CGPointMake(collectionView.contentOffset.x, -10.0f)]; 
    } 
} 

重置contentOffset只要稍有改变,这工作得很好,但contentOffset改变的同时拖动和复位,只有当用户释放细胞发生,所以有延迟。不知何故,我可以在拖动时锁定contentOffset吗?

我认为这是值得一提我的看法结构目前

UIScrollView 
    UICollectionView 
    UICollectionView (the one that has drag-drop enabled) 

父滚动型统一内收藏的两个涡旋,所以这可能是一个问题。当收集由contentOffset滚动到上面,稍微侵入它上面的集合。

回答

0

我意识到该项目被使用LXReorderableCollectionViewFlowLayout框架拖动和UICollectionViews下降,所以检查该源代码,发现该黄柏拖出集合的方法是

- (void)handleScroll:(NSTimer *)timer 

所以我加在case LXScrollingDirectionUp有点检查有一个最大的优势弥补,我设置为类的属性,像下面

// distance calculated above: how much to scroll based on drag action 
if (distance + contentOffset.y > _maxScrollingEdgeOffset.top) { 
    distance = 0; 
} 

这定了!