2016-11-23 62 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

相关问题