创建圆形布局
圆形布局是一种醒目的排版方式,他会将试图里的内容绕着某个中心区域来排布,这种布局方式很好的演示了如何在创建条目和删除条目的时候,把操作过程以动画形式展现出来。
通过collectionViewContentSize方法把视图内容的尺寸设为固定值。由于它明确的创建了一块固定不变的排版区域,所以集合视图不会再滚动了。代码还会在prepareLayout方法中进行计算,以便进一步向内缩小排版区域。屏幕的高度与屏幕的宽度之中较小的值,决定了圆的半径。无论屏幕方向如何改变,圆的半径总保持不变。
@implementation CircleLayout
{
NSInteger numberOfItems;
CGPoint centerPoint;
CGFloat radius;
NSMutableArray *insertedIndexPaths;
NSMutableArray * deletedIndexPaths;
}
- (void)prepareLayout
{
[super prepareLayout];
CGSize size = self.collectionView.frame.size;
numberOfItems = [self.collectionView numberOfItemsInSection:0];
centerPoint = CGPointMake(size.width / 2, size.height / 2);
radius = MIN(size.width, size.height) / 3;
insertedIndexPaths = [NSMutableArray array];
deletedIndexPaths = [NSMutableArray array];
}
- (CGSize)collectionViewContentSize
{
return self.collectionView.frame.size;
}
- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPat