自定义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 ...
随机推荐
- Ansible介绍
第一章 ansible服务介绍 1.1 ansible批量管理服务概述 是基于python语言开发的自动化软件工具 是基于SSH远程管理服务实现远程主机批量管理 1.2 ansible批量管理服务意义 ...
- (一)环境搭建——Django
实验环境准备: 安装django # cmd中 pip install Django 第一个django项目HelloWorld # 在D:/Python test 下创建一个helloworld项目 ...
- vue之事件处理
一.事件处理方法 1.格式 完整格式:v-on:事件名="函数名" 或 v-on:事件名="函数名(参数……)" 缩写格式:@事件名="函数名&qu ...
- input 实现一次性上传文件
在实际项目中可能会用到,上传多个文件请求一次接口,因此,主要代码 $('#tabList').on('click','.resetWorkStatus',function(){ var that = ...
- leetcood学习笔记-58-最后一个单词的长度
题目描述: 第一次解答: class Solution: def lengthOfLastWord(self, s: str) -> int: L=s.strip().split(" ...
- Ruby 中文编码
Ruby 中文编码 前面章节中我们已经学会了如何用 Ruby 输出 "Hello, World!",英文没有问题,但是如果你输出中文字符"你好,世界"就有可能会 ...
- Photon Server的服务器端配置
Photon Server与Unity3D的交互分为3篇博文实现 (1)Photon Server的服务器端配置 (2)Photon Server的Unity3D客户端配置 (3)Photon Ser ...
- 剑指offer——11矩阵覆盖
题目描述 我们可以用2*1的小矩形横着或者竖着去覆盖更大的矩形.请问用n个2*1的小矩形无重叠地覆盖一个2*n的大矩形,总共有多少种方法? 题解: 使用递归或者动态规划,明显,递归没有动态规划优 ...
- 春节跳槽最新Java面试题及答案整理
今天大部分码农同学已经上班了吧,最近也是跳槽人才流动的高峰期,拿了年终奖,找找更好的机会. 小编也面了几家公司了,回来整理下面经分享给大家做个参考.有很多,暂时先分享20道,后续更多会陆续整理分享出来 ...
- springboot + ajax + mybatis 实现批量删除
实现思路: 1. checkbox全选获取批量删除的id数组 2. ajax以字符串的形式将id数组传给控制器 3. 控制器将字符串分割成List数组作为参数传给mapper 具体代码: 1. 前端代 ...