CircleLayout
2024-08-22 17:42:46
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;
}
最新文章
- Tomcat7.0+ web.xml问题
- MyBatis Generator作为maven插件自动生成增删改查代码及配置文件例子
- PHPStorm XDebug的安装
- Linux查看系统信息的一些命令及查看已安装软件包的命令
- phpcms采集地址中为相对路径解决方法
- Java、fileless恶意软件威胁桌面安全
- FreeMarker笔记 第四章 其它
- spring mvc源码解析
- 基于Qt的信号分析简单应用软件的设计
- idea使用笔记
- Cretiria查询应用(一)
- XSS漏洞的分类
- 【重磅】PRO基础版免费,是时候和ExtJS说再见了!
- Windows 10 IoT Serials 11 – 如何设置微软认知服务中EndPoint
- JS的document.links函数使用示例
- 微信内置浏览器在使用video标签时(安卓)默认全屏的原因及解决办法
- Linux基础命令---文本格式转换expand,unexpand
- C#里的SubString和Convert.ToDateTime
- JavaScript 开闭原则OCP
- python - http请求带Authorization
热门文章
- 《c程序设计语言》读书笔记--统计字符数
- Android内存管理(2)HUNTING YOUR LEAKS: MEMORY MANAGEMENT IN ANDROID PART 2
- [CCF2015.12]题解
- 关于android软键盘enter键的替换与事件监听
- AWS 之Load Balance篇
- Android Fragment 真正的完全解析(上) (转载)
- android studio sqlite操作代码片段
- HDU 4324 (拓扑排序) Triangle LOVE
- UVa 1442 (线性扫描) Cave
- 微信开发小结-PHP