自定义Collection View布局

containers),对他们真实的内容(contents)毫不知情。
layout也可以在单行或单列中布局cell。实际上,UITableView的布局可以想象成flow layout的一种特殊情况。
views。
view中的注册。同样的方法也可以用在supplementary view上,前提是你使用了UICollectionViewFlowLayout。如果没有,你只能通过调用registerClass:或者registerNib:方法手动注册视图类了。你需要在viewDidLoad中做这些操作。

view并且返回足够大的内容宽度,这会使得用户感觉在两个方向上滑动自由。
- - (CGSize)collectionViewContentSize
- {
- // Don't scroll horizontally
- CGFloat contentWidth = self.collectionView.bounds.size.width;
- // Scroll vertically to display a full day
- CGFloat contentHeight = DayHeaderHeight + (HeightPerHour * HoursPerDay);
- CGSize contentSize = CGSizeMake(contentWidth, contentHeight);
- return contentSize;
- }
view会将kind字符传回到你的数据源。记住supplementary和decoration views的数量和种类完全由布局控制。你不会受到headers和footers的限制。
- - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
- {
- NSMutableArray *layoutAttributes = [NSMutableArray array];
- // Cells
- // We call a custom helper method -indexPathsOfItemsInRect: here
- // which computes the index paths of the cells that should be included
- // in rect.
- NSArray *visibleIndexPaths = [self indexPathsOfItemsInRect:rect];
- for (NSIndexPath *indexPath in visibleIndexPaths) {
- UICollectionViewLayoutAttributes *attributes =
- [self layoutAttributesForItemAtIndexPath:indexPath];
- [layoutAttributes addObject:attributes];
- }
- // Supplementary views
- NSArray *dayHeaderViewIndexPaths = [self indexPathsOfDayHeaderViewsInRect:rect];
- for (NSIndexPath *indexPath in dayHeaderViewIndexPaths) {
- UICollectionViewLayoutAttributes *attributes =
- [self layoutAttributesForSupplementaryViewOfKind:@"DayHeaderView"
- atIndexPath:indexPath];
- [layoutAttributes addObject:attributes];
- }
- NSArray *hourHeaderViewIndexPaths = [self indexPathsOfHourHeaderViewsInRect:rect];
- for (NSIndexPath *indexPath in hourHeaderViewIndexPaths) {
- UICollectionViewLayoutAttributes *attributes =
- [self layoutAttributesForSupplementaryViewOfKind:@"HourHeaderView"
- atIndexPath:indexPath];
- [layoutAttributes addObject:attributes];
- }
- return layoutAttributes;
- }
- - (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath
- {
- CalendarDataSource *dataSource = self.collectionView.dataSource;
- id<CalendarEvent> event = [dataSource eventAtIndexPath:indexPath];
- UICollectionViewLayoutAttributes *attributes =
- [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath];
- attributes.frame = [self frameForEvent:event];
- return attributes;
- }
和 +layoutAttributesForDecorationViewOfKind:withIndexPath:,他们是用来创建正确的布局属性对象。
- - (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds
- {
- CGRect oldBounds = self.collectionView.bounds;
- if (CGRectGetWidth(newBounds) != CGRectGetWidth(oldBounds)) {
- return YES;
- }
- return NO;
- }
view不仅向其布局请求cell正常状态下的布局属性,同时还请求其初始的布局属性,比如,需要在开始有插入动画的cell。collection view会简单的创建一个animation block,并在这个block中,将所有cell的属性从初始(initial)状态改变到常态(normal)。
prescribes.)。
自定义Collection View布局的更多相关文章
- 自定义 Collection View 布局
自定义 Collection View 布局 answer-huang 29 Mar 2014 分享文章 UICollectionView 在 iOS6 中第一次被引入,也是 UIKit 视图类中的一 ...
- iOS系列译文:自定义Collection View布局
原文出处: Ole Begemann 译文出处: 黄爱武(@answer-huang).欢迎加入技术翻译小组. UICollectionView在iOS6中第一次被介绍,也是UIKit视图类中的一 ...
- IOS UIView 03- 自定义 Collection View 布局
注:本人是翻译过来,并且加上本人的一点见解. 前言 UICollectionView 在 iOS6 中第一次被引入,也是 UIKit 视图类中的一颗新星.它和 UITableView 共享一套 API ...
- Collection View 自定义布局(custom flow layout)
Collection view自定义布局 一般我们自定义布局都会新建一个类,继承自UICollectionViewFlowLayout,然后重写几个方法: prepareLayout():当准备开始布 ...
- Customize the View Items Layout 自定义视图项目布局
In this lesson, you will learn how to customize the default editor layout in a Detail View. For this ...
- Collection View Programming Guide for iOS---(七)---Custom Layouts: A Worked Example
Custom Layouts: A Worked Example Creating a custom collection view layout is simple with straightfor ...
- Collection View Programming Guide for iOS---(六)---Creating Custom Layouts
Creating Custom Layouts 创建自定义布局 Before you start building custom layouts, consider whether doing so ...
- Collection View Programming Guide for iOS---(五)---Incorporating Gesture Support
Incorporating Gesture Support 结合手势支持 You can add greater interactivity to your collection views th ...
- Collection View Programming Guide for iOS---(四)---Using the Flow Layout
Using the Flow Layout使用流布局 The UICollectionViewFlowLayout class is a concrete layout object that y ...
随机推荐
- ARM 寄存器 和 工作模式了解
一. ARM 工作模式 1. ARM7,ARM9,ARM11,处理器有 7 种工作模式:Cortex-A 多了一个监视模式(Monitor) 2. 用户模式:非特权模式,大部分任务执行在这种模式 ...
- 笔记40 Spring Web Flow——订单流程(构建订单)
二.订单子流程 在识别完顾客之后,主流程的下一件事情就是确定他们想要什么类型 的披萨.订单子流程就是用于提示用户创建披萨并将其放入订单中 的,如下图所示. showOrder状态位于订单子流程的中心位 ...
- vue之TodoMVC项目实战
一.初始化项目 1.下载模板 进入github中https://github.com/tastejs/todomvc-app-template,并且在命令行将其clone下来 git clone ht ...
- Eclipse导入Maven项目解决Build Path不能配置问题
Eclipse Mars Release (4.5.0)导入Maven项目时,发现项目Build Path不能配置,如下图所示: 解决办法: 1修改Project Facets 项目右键---> ...
- 通过statCounter计算给定的RDD[Double]的统计信息的方法
需求1:给定一个RDD[Double],进行计算,该RDD的统计信息(count,mean,stdev,max,min) 代码: def main(args: Array[String]): Unit ...
- 关于canvas绘制图像模糊问题
前段时间在做项目的裁剪并上传图像功能的时候,发现裁剪后展示的图像比较模糊,之后去百度上搜索了一下,看到有一个解决方案是设置canvas的宽高为css宽高的3倍,使用后感觉效果很好,当时就没管原理接着做 ...
- 记一次为解决Python读取PDF文件的Shell操作
目录 一.背景 二.问题 三.解决 四.一顿分析及 Shell 操作 五.后续 一.背景 本想将 PDF 文件转换为 Word 文档,然后网上搜索了一下发现有挺多转换的软件.有的是免费的.收费,咱也不 ...
- 依赖背包变形(经典)——poj1155
这个题用优化后的依赖背包做难以实现,所以用常规的泛化物品的和来做即可 每个节点的容量定义为这个节点下的叶子结点个数,dp[u][j]用来表示节点u下选取j个物品的最大收益,最后从m-0查询dp[1][ ...
- NX二次开发-NXOpen::WCS Class Reference
NX11+VS2013 #include <NXOpen/Part.hxx> #include <NXOpen/PartCollection.hxx> #include < ...
- 如何通过编程发现Java死锁
本文由 ImportNew - rookie_sam 翻译自 Dzone.欢迎加入翻译小组.转载请见文末要求. 死锁是指,两个或多个动作一直在等待其他动作完成而使得所有动作都始终处在阻塞的状态.想要在 ...