自己写了一个简单的自定义collectionView布局方法,能实现collectionView滑动时cell随着偏移量具有缩放效果;虽然看起来没什么特效,但是加入了transform3D属性,可以加以拓展。现在把主要的布局方法写下来,如下所示:
- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewLayoutAttributes *attributes = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath];
attributes.size = CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT);
attributes.center = CGPointMake(indexPath.item*SCREEN_WIDTH + SCREEN_WIDTH/2, SCREEN_HEIGHT/2);
UICollectionView *collection = self.collectionView;
CGFloat conF = collection.contentOffset.x;
CGFloat singleA = M_PI*90/180;
CGFloat angleLast;
NSInteger detItem = (NSInteger)conF/SCREEN_WIDTH;
if (indexPath.item == detItem) {
angleLast = ((conF/SCREEN_WIDTH)-detItem)*singleA;
} else if (indexPath.item == (detItem + 1)) {
angleLast = (detItem+1-(conF/SCREEN_WIDTH))*singleA;
} else {
angleLast = 0;
}
CATransform3D transform = CATransform3DIdentity;
transform = CATransform3DMakeRotation(angleLast, 1, 0, 0);
attributes.transform3D = transform;
return attributes;
}