Ios UICollectionViewCell透视变换显示/消失
我的目标是创建一个UICollectionView,与下图中的一样,它的单元格在退出和进入时会随着透视而褪色。我的scrollViewDidScroll委托函数如下所示:Ios UICollectionViewCell透视变换显示/消失,ios,uicollectionview,catransform3d,Ios,Uicollectionview,Catransform3d,我的目标是创建一个UICollectionView,与下图中的一样,它的单元格在退出和进入时会随着透视而褪色。我的scrollViewDidScroll委托函数如下所示: NSArray *rows = [self.feedCollectionView indexPathsForVisibleItems]; for (NSIndexPath *path in rows) { if (path.row != 1) { continue; } UICollec
NSArray *rows = [self.feedCollectionView indexPathsForVisibleItems];
for (NSIndexPath *path in rows) {
if (path.row != 1) {
continue;
}
UICollectionViewCell *cell = [self.feedCollectionView cellForItemAtIndexPath:path];
float height = cell.frame.size.height;
float position = cell.frame.origin.y - scrollView.contentOffset.y;
float offsetFromBottom = self.feedCollectionView.frame.size.height- position;
float fraction = MAX(((height - offsetFromBottom)/height), 0);
//float angleFormula = -((height - offsetFromBottom)/height)*M_PI/2;
float rotation = MIN(-((height - offsetFromBottom)/height)*M_PI/2, 0);
CGRect frame = cell.frame;
[self setAnchorPoint:CGPointMake(0.5, 0.0) forView:cell];
cell.frame = frame;
CATransform3D transform = CATransform3DIdentity;
transform.m34 = -1.0/(height * 4.6666667);
transform = CATransform3DRotate(transform, rotation, 1, 0, 0);
[cell.layer setAnchorPoint:CGPointMake(0.5, 0.0)];
cell.layer.sublayerTransform = transform;
float delta = asinf(fraction);
[cell.layer setTransform:CATransform3DMakeRotation(delta, 1, 0, 0)];
}
不幸的是,当细胞被加载时,setAnchorPoint将细胞移出其自然位置,整个collectionView变得混乱。但是,如果不将定位点设置为新位置,则不可能获得良好的透视变换,因为这样可以确保单元的上边缘不会变宽
最初出现在屏幕上的细胞一直很好,直到它们消失并重新出现,此时画面神秘地发生了变化。所有不在屏幕上的单元格最初都有问题。UICollectionView似乎在设置其单元格的anchorPoint属性时遇到问题。是否有任何方法可以修改透视变换,使其表现为锚点不同,或者有任何方法可以使collectionview接受其单元格可能具有不同的锚点
回答我自己的问题,我想
解决方案是执行转换并调整单元格contentView上的定位点。您能提供更多详细信息吗?