zoukankan      html  css  js  c++  java
  • CircleLayout

    CircleLayout
    
    https://developer.apple.com/library/ios/samplecode/CircleLayout/Introduction/Intro.html#//apple_ref/doc/uid/DTS40012315
    
    
    //1.
    
    [self.collectionView performBatchUpdates:^{
        [self.collectionView reloadItemsAtIndexPaths:@[indexPath]];
    } completion:^(BOOL finished) {
    
    }];
    
    //这个方法会在第一个 block 中处理 insert/delete/reload/move 等操作,等操作完成之后会执行第二个block。
    
    //2.自定义UICollectionViewLayout 类 CircleLayout
    _viewController = [[ViewController alloc] initWithCollectionViewLayout:[[CircleLayout alloc] init]];
    
    //(1)继承父类方法
    -(void)prepareLayout
    {
        [super prepareLayout];
        //在此方法中初始化此类的属性
        CGSize size = self.collectionView.frame.size;
       _cellCount = [[self collectionView] numberOfItemsInSection:0];
       _center = CGPointMake(size.width / 2.0, size.height / 2.0);
       _radius = MIN(size.width, size.height) / 2.5;
    }
    
    //(2)返回CollectionView 内容页的大小
    -(CGSize)collectionViewContentSize
    {
        return [self collectionView].frame.size;
    }
    
    //(3)在rect区域内 返回每个cell的LayoutAttributes
    -(NSArray*)layoutAttributesForElementsInRect:(CGRect)rect
    {
        NSMutableArray* attributes = [NSMutableArray array];
        for (NSInteger i=0 ; i < self.cellCount; i++) {
            NSIndexPath* indexPath = [NSIndexPath indexPathForItem:i inSection:0];
            [attributes addObject:[self layoutAttributesForItemAtIndexPath:indexPath]];
        }
        return attributes;
    }
    //(4) 确定 attributes 的size 和 center
    - (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)path
    {
        UICollectionViewLayoutAttributes* attributes = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:path];
        attributes.size = CGSizeMake(ITEM_SIZE, ITEM_SIZE);
        attributes.center = CGPointMake(_center.x + _radius * cosf(2 * path.item * M_PI / _cellCount),
                                        _center.y + _radius * sinf(2 * path.item * M_PI / _cellCount));
        return attributes;
    }
    
  • 相关阅读:
    八十五:redis之redis的事物、发布和订阅操作 (2019-11-18 22:54)
    八十四:redis之redis的集合、哈希操作
    八十三:redis之redis的字符串、过期时间、列表操作
    八十三:redis之redis的使用场景和安装
    八十二:memcached之python操作memcached
    八十一:memcached之telnet操作memcached
    八十:memcached之安装与参数
    MySQL篇之Navicat可视化工具
    MySQL数据库篇之多表查询
    MySQL数据库篇之单表查询
  • 原文地址:https://www.cnblogs.com/levy/p/4801244.html
Copyright © 2011-2022 走看看