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;
}

最新文章

  1. Tomcat7.0+ web.xml问题
  2. MyBatis Generator作为maven插件自动生成增删改查代码及配置文件例子
  3. PHPStorm XDebug的安装
  4. Linux查看系统信息的一些命令及查看已安装软件包的命令
  5. phpcms采集地址中为相对路径解决方法
  6. Java、fileless恶意软件威胁桌面安全
  7. FreeMarker笔记 第四章 其它
  8. spring mvc源码解析
  9. 基于Qt的信号分析简单应用软件的设计
  10. idea使用笔记
  11. Cretiria查询应用(一)
  12. XSS漏洞的分类
  13. 【重磅】PRO基础版免费,是时候和ExtJS说再见了!
  14. Windows 10 IoT Serials 11 – 如何设置微软认知服务中EndPoint
  15. JS的document.links函数使用示例
  16. 微信内置浏览器在使用video标签时(安卓)默认全屏的原因及解决办法
  17. Linux基础命令---文本格式转换expand,unexpand
  18. C#里的SubString和Convert.ToDateTime
  19. JavaScript 开闭原则OCP
  20. python - http请求带Authorization

热门文章

  1. 《c程序设计语言》读书笔记--统计字符数
  2. Android内存管理(2)HUNTING YOUR LEAKS: MEMORY MANAGEMENT IN ANDROID PART 2
  3. [CCF2015.12]题解
  4. 关于android软键盘enter键的替换与事件监听
  5. AWS 之Load Balance篇
  6. Android Fragment 真正的完全解析(上) (转载)
  7. android studio sqlite操作代码片段
  8. HDU 4324 (拓扑排序) Triangle LOVE
  9. UVa 1442 (线性扫描) Cave
  10. 微信开发小结-PHP