2015-12-01 11 views
-1

我想同時滾動兩個UICollectionView。當我滾動第一個集合視圖,然後滾動底部UIcollectionview(Collectionview2)。如何在ObjC中滾動並行兩個uicollectionview

目前我正在使用scrollViewDidEndDecelerating方法,但它不能正常工作。 請給予任何消化。

see Image...

目前我使用下面的代碼...

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{ 
CGPoint centerPoint = CGPointMake(self.clnViewWorkoutTitles.center.x + self.clnViewWorkoutTitles.contentOffset.x, 
             self.clnViewWorkoutTitles.center.y + self.clnViewWorkoutTitles.contentOffset.y); 
    NSIndexPath *centerCellIndexPath = [self.clnViewWorkoutTitles indexPathForItemAtPoint:centerPoint]; 
    [self.clnViewWorkoutContent scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:centerCellIndexPath.item inSection:0] atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES]; 
    [self.clnViewWorkoutTitles scrollToItemAtIndexPath:centerCellIndexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];} 
+0

你能顯示當前的代碼,你有嗎? –

+0

@Otávio肯定請檢查我已更新的問題。 – Vvk

+0

我可以在你的屏幕截圖上看到_cells_;第一個集合視圖在哪裏?第二個在哪裏? _「不能正常工作」_是什麼意思?它是如何工作的?你期望什麼? – holex

回答

1

你也可以一樣,如果你使用的是兩個收集視圖collectionview.tag ==使用的CollectionView代表101和collectionview.tag = = 102。 在你第一次的CollectionView三種細胞都顯示

- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath{ 

NSLog(@"%li",(long)indexPath.row); 

if(collectionView.tag == 101){ 

    if(fmod(indexPath.row, 3) == 1 && indexPath.row != 1){ 

     if (scrollDirection == ScrollDirectionLeft) { 
     [self.collectionView2 setContentOffset:CGPointMake(currScrollXPos+300, 0) animated:YES]; 
     currScrollXPos = currScrollXPos+300; 
     } 
     if (scrollDirection == ScrollDirectionRight) { 
      [self.collectionView2 setContentOffset:CGPointMake(currScrollXPos-300, 0) animated:YES]; 
      currScrollXPos = currScrollXPos-300; 
     } 
    } 

}