0
我的目標是創建一個UICollectionView,它像下圖中的那個一樣,在退出和輸入時具有淡入透視圖的單元。我scrollViewDidScroll委託功能如下:UICollectionViewCell透視變換出現/消失
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屬性。有沒有辦法將透視轉換修改爲像anchorPoint不同,或者讓collectionview接受其單元可能具有不同錨點的方法?
你能提供更多細節嗎? – KostiaZzz 2017-06-21 11:54:39