Ios UIcollectionViewCells在更改其布局属性时表现异常
我想查看像safari最近的标签 我可以在一定程度上创造,但如果细胞数量增加,它看起来像 而且,当我选择任何单元格时,它也不会返回正确的索引路径 这是我使用的代码Ios UIcollectionViewCells在更改其布局属性时表现异常,ios,uicollectionview,uicollectionviewcell,uicollectionviewlayout,Ios,Uicollectionview,Uicollectionviewcell,Uicollectionviewlayout,我想查看像safari最近的标签 我可以在一定程度上创造,但如果细胞数量增加,它看起来像 而且,当我选择任何单元格时,它也不会返回正确的索引路径 这是我使用的代码 -(UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath { NSInteger index = indexPath.row; NSInteger total = [self.coll
-(UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath
{
NSInteger index = indexPath.row;
NSInteger total = [self.collectionView numberOfItemsInSection:0];
UICollectionViewLayoutAttributes* attr = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath];
attr.frame = CGRectMake(10, 0, self.collectionView.frame.size.width - 20, 350);
CATransform3D transform = CATransform3DIdentity;
transform.m34 = 1.0/-500;
if (indexPath.row+1 == total)
{
transform = CATransform3DTranslate(transform, 0, (CARD_SPACING * index), 15);
attr.transform3D = CATransform3DRotate(transform, 0, 0, 0, 0);
}
else
{
transform = CATransform3DTranslate(transform, 0, (CARD_SPACING * index), 0);
attr.transform3D = CATransform3DRotate(transform, -(M_PI*18)/180, 1, 0, 0);
}
return attr;
}
这只是一个粗略的代码。我走对了还是错了,谁能帮我一下吗。因为我第一次创建自定义布局
如果这个完整的代码不正确,请告诉我合适的方法来实现它
这段代码对3或4个单元格运行良好,但随着我增加单元格数量,它看起来很奇怪