ios 创建圆形布局

本文介绍了如何在iOS中创建圆形布局,包括在创建和删除条目时的动画效果。通过设置collectionViewContentSize和prepareLayout方法实现固定大小的圆形布局。文章详细解释了布局计算方法,以及如何通过initialLayoutAttributesForAppearingItemAtIndexPath和finalLayoutAttributesForDisappearingItemAtIndexPath方法实现动画效果,增强了圆形布局的实用性。
摘要由CSDN通过智能技术生成

创建圆形布局

    圆形布局是一种醒目的排版方式,他会将试图里的内容绕着某个中心区域来排布,这种布局方式很好的演示了如何在创建条目和删除条目的时候,把操作过程以动画形式展现出来。


    通过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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值