我正在为UICollectionView设计一个覆盖流样式的布局。这是一个足够简单的概念,只是为了使它更容易,有大约100个关于这个主题的教程。然而,正如任何做转换的人都知道的那样,m34是一个神奇的数字。然而,一旦我设置它,以获得一些角度,我的旋转,视图消失。只有在旋转接近于0时才会出现。
我怀疑这是一个界限/zIndex问题,然而,经过几天与zIndexes和剪辑调整,细胞拒绝出现。任何帮助都是非常感谢的。
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
{
NSArray *array = [super layoutAttributesForElementsInRect:rect];
CGRect visibleRect = (CGRect){self.collectionView.contentOffset, self.collectionView.bounds.size};
CGFloat maxDistance = visibleRect.size.width / 2.0;
CGFloat maxRotation = M_PI_2;
[array enumerateObjectsUsingBlock:^(UICollectionViewLayoutAttributes * attributes, NSUInteger idx, BOOL *stop) {
CGFloat distanceFromCenter = CGRectGetMidX(visibleRect) - attributes.center.x;
CGFloat percentageFromCenter = distanceFromCenter / maxDistance;
percentageFromCenter = MIN(percentageFromCenter, 1.0);
percentageFromCenter = MAX(percentageFromCenter, -1.0);
CGFloat angle = percentageFromCenter * maxRotation;
CATransform3D transform = CATransform3DIdentity;
// transform.m34 = 1.0 / -800.0;
transform = CATransform3DRotate(transform, angle, 0.0, 1.0, 0.0);
attributes.transform3D = transform;
}];
return array;
}发布于 2013-07-18 02:10:45
所以,多亏了推特上的一个@mpospese。问题不在于m34值本身。它具有UICollectionView的一个特殊特性。
当帧高度超过集合视图的高度时,删除单元格
因此,在我的例子中,我有一个专门设计的UICollectionViewLayout,用于获取UICollectionView的height,并将其用于单元格的高度。问题是,当m34被考虑在内时,它明显地调整了帧,因此超过了界限。与其像大多数UIView操作那样只裁剪单元格,还可以直接指向问题,UICollectionView实际上会自动删除所有单元格,只要它们能够擦除外部边界。
https://stackoverflow.com/questions/17712821
复制相似问题