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

這定了!

相關問題