2016-11-23 65 views
0

當我開始滾動時,我有UICollectionView與customLayOut, 我改變了應該開始可見的單元格的x座標 - 以便從開始時可見。如何把UICollectionView中的單元格放在另一個上

-(void)layoutSubviewsWithAttributes:(NSMutableArray *)theAttributes { 
CGFloat halfScreen = [UIScreen mainScreen].bounds.size.width/2; 
CGPoint startOfScreen = CGPointMake(self.timeLineCollection.bounds.origin.x, 25.f); 
for(UICollectionViewLayoutAttributes *attribute in theAttributes) { 
    if(CGRectContainsPoint(attribute.frame, startOfScreen)) { 
    NSLog(@"Intersect %@", NSStringFromCGRect(attribute.frame)); 
    attribute.frame = CGRectMake(startOfScreen.x, startOfScreen.y, attribute.frame.size.width, attribute.frame.size.height); 
} 

}

,但在某些情況下,該小區出現在下一個單元格(錯誤的行爲)的頂部,

enter image description here

另一次,下下一次該小區一個細胞(因爲我需要它被放置)。

enter image description here

莫非你的意見,如何排序的細胞進行分級一個放置在另一個(如卡)。

非常感謝您的幫助。

+1

按照本教程:https://www.raywenderlich.com/107687/uicollectionview-custom-layout-tutorial-spinning-wheel – shallowThought

+0

@shallowThought,謝謝你,但我沒有看到解決方案,我的問題有 – Melany

回答

0

UICollectionViewLayoutAttributes具有這樣的屬性作爲zIndex,即 - 指定項目的上Z軸位置。 因此,要告訴單元格被一個接一個地設置,我只需設置每個屬性zIndex - 每個單元格的編號,並將它放在customLayOut中。

for (NSInteger item = 0; item < self.cellCountPrograms; item++) { 
    indexPath = [NSIndexPath indexPathForItem:item inSection:0]; 
    UICollectionViewLayoutAttributes *itemAttributes = 
    [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath]; 
    itemAttributes.frame = [self frameForItemAtIndexPath:indexPath]; 
    itemAttributes.zIndex = item; 
    cellProgramLayoutInfo[indexPath] = itemAttributes; 
} 
1

試試這與負值可能會幫助,因爲我還沒有嘗試,但我相信它應該這樣工作。

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section 
{ 
    return -5.0; 
} 
+0

非常感謝你的建議,但它並沒有幫助,不幸的是。 – Melany

相關問題