如何将 UICollectionView 中的单元格放在另一个上
How put cells in UICollectionView one on another
我有带有 customLayOut 的 UICollectionView,当我开始滚动时,
我更改了应该开始可见的单元格的 x 坐标 - 为了从一开始就可见。
-(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);
}
}
但在某些情况下,此单元格出现在下一个单元格的顶部(错误行为),
还有一次,那个单元格在下一个单元格下面(因为我需要放置它)。
你能建议一下,如何对要分层放置的单元格进行排序(如卡片)。
提前感谢您的帮助。
用负值试试这个可能会有帮助,因为我还没有尝试过,但我相信它应该像这样工作。
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
return -5.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;
}
我有带有 customLayOut 的 UICollectionView,当我开始滚动时, 我更改了应该开始可见的单元格的 x 坐标 - 为了从一开始就可见。
-(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);
}
}
但在某些情况下,此单元格出现在下一个单元格的顶部(错误行为),
还有一次,那个单元格在下一个单元格下面(因为我需要放置它)。
你能建议一下,如何对要分层放置的单元格进行排序(如卡片)。
提前感谢您的帮助。
用负值试试这个可能会有帮助,因为我还没有尝试过,但我相信它应该像这样工作。
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
return -5.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;
}