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;
}
CircleLayout的更多相关文章
- iOS6新特征:UICollectionView高级使用示例之CircleLayout
		DEMO 下面再看看Demo运行的效果图,通过这样的一个Demo,我们可以看出,使用UICollectionView可以很方便的制作出照片浏览等应用.并且需要开发者写的代码也不多. 程序刚刚启 ... 
- ios项目里扒出来的json文件
		p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo; color: #000000 } p.p2 { margin: 0.0px 0. ... 
- Github上关于iOS的各种开源项目集合(强烈建议大家收藏,查看,总有一款你需要)
		下拉刷新 EGOTableViewPullRefresh - 最早的下拉刷新控件. SVPullToRefresh - 下拉刷新控件. MJRefresh - 仅需一行代码就可以为UITableVie ... 
- Advanced Collection Views and Building Custom Layouts
		Advanced Collection Views and Building Custom Layouts UICollectionView的结构回顾 首先回顾一下Collection View的构成 ... 
- iOS - 开发类库
		开发类库 UI 项目名称 项目信息 1.MJRefresh 仅需一行代码就可以为UITableView或者CollectionView加上下拉刷新或者上拉刷新功能.可以自定义上下拉刷新的文字说明. ... 
- iOS及Mac开源项目和学习资料【超级全面】
		UI 下拉刷新 EGOTableViewPullRefresh – 最早的下拉刷新控件. SVPullToRefresh – 下拉刷新控件. MJRefresh – 仅需一行代码就可以为UITable ... 
- python数据结构与算法——图的基本实现及迭代器
		本文参考自<复杂性思考>一书的第二章,并给出这一章节里我的习题解答. (这书不到120页纸,要卖50块!!,一开始以为很厚的样子,拿回来一看,尼玛.....代码很少,给点提示,然后让读者自 ... 
- Android开源代码分享
		一.AppMsg实现自定义Toast. github下载地址 二.CircleImageView实现带边框圆形头像. github下载地址 ... 
- iOS:iOS开发非常全的三方库、插件等等
		iOS开发非常全的三方库.插件等等 github排名:https://github.com/trending, github搜索:https://github.com/search. 此文章转自git ... 
随机推荐
- YTU 2617: B C++时间类的运算符重载
			2617: B C++时间类的运算符重载 时间限制: 1 Sec 内存限制: 128 MB 提交: 284 解决: 108 题目描述 C++时间类的运算符重载 定义一个时间类Time,其数据成员为 ... 
- Top 10 steps to optimize data access in SQL Server
			2009年04月28日 Top 10 steps to optimize data access in SQL Server: Part I (use indexing) 2009年06月01日 To ... 
- 谈谈 char *num="123";和char num[4]="123";的区别
			最近写程序的时候发现这样一个问题 #include<iostream> #include <string.h> using namespace std; void revers ... 
- JS里面匿名函数的调用 & 变量作用域的实验
			参考 http://www.educity.cn/wenda/54753.html 已实验验证结果正确. 1.下列哪些正确?(B.C) A.function(){ alert("Here!& ... 
- Codeforces Round #272 (Div. 2)  D. Dreamoon and Sets (思维 数学  规律)
			题目链接 题意: 1-m中,四个数凑成一组,满足任意2个数的gcd=k,求一个最小的m使得凑成n组解.并输出 分析: 直接粘一下两个很有意思的分析.. 分析1: 那我们就弄成每组数字都互质,然后全体乘 ... 
- IOS中字符串操作
			1.比较大小 - (NSComparisonResult)compare:(NSString *)string; 返回值NSComparisonResult有3种情况: NSOrderedAscend ... 
- POJ 1861 Network (MST)
			题意:求解最小生成树,以及最小瓶颈生成树上的瓶颈边. 思路:只是求最小生成树即可.瓶颈边就是生成树上权值最大的那条边. //#include <bits/stdc++.h> #includ ... 
- Spark RDD操作(1)
			https://www.zybuluo.com/jewes/note/35032 RDD是什么? RDD是Spark中的抽象数据结构类型,任何数据在Spark中都被表示为RDD.从编程的角度来看,RD ... 
- phpcms还原被删除的栏目
			1.在这个目录下/caches/bakup/default导出文件category.sql 2.登录网站的数据管理页面phpmyadmin 3.导入数据库选择category.sql 4.登陆网站后台 ... 
- 18个jQuery Mobile开发贴士和教程
			jQuery Mobile 是 jQuery 在手机上和平板设备上的版本.jQuery Mobile 不仅会给主流移动平台带来jQuery核心库,而且会发布一个完整统一的jQuery移动UI框架.支持 ... 
