UIkit框架之UIcollection
1.继承链:UIScrollView:UIview:UIResponder:NSObject
2.collection view使用的数据源需要遵守UICollectionViewDataSource协议,使用 UICollectionViewCell的实例对象来创建每个单独collection cell单元来显示数据源的每个单元视图
3.为了提高重用性,最好使用一下两种方法来创建视图:
(1)使用 dequeueReusableCellWithReuseIdentifier:forIndexPath:来得到collection cell
(2)使用 dequeueReusableSupplementaryViewOfKind:withReuseIdentifier:forIndexPath:来创建补充视图
注意:但是当你使用(1)的方法的时候首先需要配置好registerClass:forCellWithReuseIdentifier: or registerNib:forCellWithReuseIdentifier: method.这些方法,不然会报错
4.为了能够互相交互的对项目进行重新布置,可以使用 beginInteractiveMovementForItemAtIndexPath:方法;当你使用手势来跟踪触发事件的时候可以使用 updateInteractiveMovementTargetPosition:方法来返回触发的点;当你结束跟踪的时候可以使用 endInteractiveMovement or cancelInteractiveMovement方法来结束交互和更新视图。
5. UICollectionViewController这个类提供有默认的手势管理器来管理重新排列collection view,为了能够使用手势你需要设置 installsStandardGestureForInteractiveMovement为yes。
6.初始化collection view
(1)- (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout :通过一个布局策略初识化CollectionView
7.配置collection view
(1)@property(nonatomic, weak) id< UICollectionViewDelegate> delegate :设置委托
(2)@property(nonatomic, weak) id< UICollectionViewDataSource> dataSource :设置数据源
(3)@property(nonatomic, strong) UIView*backgroundView :设置背景视图
8.创建collection cell
(1)- (void)registerClass:(Class)cellClassforCellWithReuseIdentifier:(NSString *)identifier :从一个class文件进行cell(item)的注册
(2)- (void)registerNib:(UINib *)nibforCellWithReuseIdentifier:(NSString *)identifier : 从一个nib文件进行cell(item)的注册
(3)//下面两个方法与上面相似,这里注册的是头视图或者尾视图的类
//其中第二个参数是设置 头视图或者尾视图 系统为我们定义好了这两个字符串
//UIKIT_EXTERN NSString *const UICollectionElementKindSectionHeader NS_AVAILABLE_IOS(6_0);
//UIKIT_EXTERN NSString *const UICollectionElementKindSectionFooter NS_AVAILABLE_IOS(6_0);
- (void)registerClass:(nullable Class)viewClass forSupplementaryViewOfKind:(NSString *)elementKind withReuseIdentifier:(NSString *)identifier;
- (void)registerNib:(nullable UINib *)nib forSupplementaryViewOfKind:(NSString *)kind withReuseIdentifier:(NSString *)identifier;
(4)- (__kindofUICollectionViewCell *)dequeueReusableCellWithReuseIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath
identifier |
The reuse identifier for the specified cell. This parameter must not be |
indexPath |
The index path specifying the location of the cell. The data source receives this information when it is asked for the cell and should just pass it along. This method uses the index path to perform additional configuration based on the cell’s position in the collection view. |
解释:从复用池中取出cell
(5)- (__kindofUICollectionReusableView *)dequeueReusableSupplementaryViewOfKind:(NSString *)elementKind withReuseIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath
elementKind |
The kind of supplementary view to retrieve. This value is defined by the layout object. This parameter must not be |
identifier |
The reuse identifier for the specified view. This parameter must not be |
indexPath |
The index path specifying the location of the supplementary view in the collection view. The data source receives this information when it is asked for the view and should just pass it along. This method uses the information to perform additional configuration based on the view’s position in the collection view. |
解释:从复用池中取出头尾视图
9.改变布局
(1)@property(nonatomic, strong) UICollectionViewLayout*collectionViewLayout :获取或设置布局
(2)- (void)setCollectionViewLayout:(UICollectionViewLayout *)layout animated:(BOOL)animated :使用动画来重新设置布局
(3)- (void)setCollectionViewLayout:(UICollectionViewLayout *)layout animated:(BOOL)animated completion:(void (^)(BOOL finished))completion :使用动画的方式来进行重新布局,并且结束后会返回一个布尔值确定转换是否成功
(4)- (UICollectionViewTransitionLayout *)startInteractiveTransitionToCollectionViewLayout:(UICollectionViewLayout *)layout completion:(UICollectionViewLayoutInteractiveTransitionCompletion)completion :开始交互式转换来进行布局,这个方法传入一个布局策略layout,系统会开始进行布局渲染,返回一个UICollectionViewTransitionLayout对象
//这个UICollectionViewTransitionLayout对象管理动画的相关属性
(5)- (void)finishInteractiveTransition :准备好动画设置后,我们需要调用下面的方法进行布局动画的展示,之后会调用上面方法的block回调
(6)- (void)cancelInteractiveTransition ://调用这个方法取消上面的布局动画设置,之后也会进行上面方法的block回调
10.重新加载内容
(1)- (void)reloadData :重新加载数据
(2)- (void)reloadSections:(NSIndexSet *)sections :重新加载分区
(3)- (void)reloadItemsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths :重新加载指定路径的item
11.获取collection view的状态
(1)- (NSInteger)numberOfSections :获取和设置分区的数量
(2)- (NSInteger)numberOfItemsInSection:(NSInteger)section :获取或者设置分区俩面里面item的数量
(3)- (NSArray<__kindofUICollectionViewCell *> *)visibleCells :获取可见cell组成的数组
12.插入、移动、删除item
(1)- (void)insertItemsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths :插入指定路径的item组成的数组
(2)- (void)moveItemAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath :把indexpath路径的item移动到newindexpath
(3)- (void)deleteItemsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths :删除指定路径的item组成的数组
13.插入、移动、删除分区
(1)- (void)insertSections:(NSIndexSet *)sections :插入指定的分区
(2)- (void)moveSection:(NSInteger)section toSection:(NSInteger)newSection :把section分区到newsection分区
(3)- (void)deleteSections:(NSIndexSet *)sections :删除指定的分区
14.重新排序item交互
(1)- (BOOL)beginInteractiveMovementForItemAtIndexPath:(NSIndexPath *)indexPath :开始指定路径item的移动交互性
(2)- (void)updateInteractiveMovementTargetPosition:(CGPoint)targetPosition :更新目标地址的移动交互性
(3)- (void)endInteractiveMovement :结束移动交互性,移动item
(4)- (void)cancelInteractiveMovement :取消移动交互性
15.管理选择
(1)@property(nonatomic) BOOL allowsSelection :是否选择
(2)@property(nonatomic) BOOL allowsMultipleSelection :是否允许多重选择
(3)- (NSArray<NSIndexPath *> *)indexPathsForSelectedItems :包含由被选item的路径组成的数组
(4)- (void)selectItemAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UICollectionViewScrollPosition)scrollPosition :移动到被选路径的item
(5)- (void)deselectItemAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated :取消指定路径的选择
16.管理focus
(1)@property(nonatomic) BOOL remembersLastFocusedIndexPath :记录最后被focus的item的路径
17.collection view和item的位置
(1)- (NSIndexPath *)indexPathForItemAtPoint:(CGPoint)point :返回进行点item的路径
(2)- (NSArray<NSIndexPath *> *)indexPathsForVisibleItems :返回由可见item组成的数组
(3)- (NSIndexPath *)indexPathForCell:(UICollectionViewCell *)cell :获得指定cell的路径
(4)- (UICollectionViewCell *)cellForItemAtIndexPath:(NSIndexPath *)indexPath :获取指定路径的cell
(5)- (NSArray<NSIndexPath *> *)indexPathsForVisibleSupplementaryElementsOfKind:(NSString *)elementKind :获取可见头尾视图的路径
(6)- (UICollectionReusableView *)supplementaryViewForElementKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath :返回指定路径的头尾视图
(7)- (NSArray<UICollectionReusableView *> *)visibleSupplementaryViewsOfKind:(NSString *)elementKind :返回可见的头尾视图
18.获取布局信息
(1)- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath :获取指定路径item的布局属性
(2)- (UICollectionViewLayoutAttributes *)layoutAttributesForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath*)indexPath :获取指定路径头尾视图的布局属性
19.滚动到视图
(1)- (void)scrollToItemAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UICollectionViewScrollPosition)scrollPosition animated:(BOOL)animated :使用动画的形式滚动到指定的路径,并设置滚动点的位置
20.collection view动画的多重变化
(1)- (void)performBatchUpdates:(void (^)(void))updates completion:(void (^)(BOOL finished))completion :同时用户可能会多次选择、取消操作,也就是说我们允许多次点击(multiple touch),为了更好处理这样操作,UICollectionView提供方法:
UIkit框架之UIcollection的更多相关文章
- Swift - 重写UIKit框架类的init初始化方法(以UITabBarController为例)
原来写了篇文章讲UITabBarController的用法,当时是从UIViewController跳转到UITabBarController页面,代码如下: 1 self.presentViewCo ...
- UIKit框架
在今后的应用程序构建中,会陆续使用各式各样的控件,因此UIKit框架的引入是必不可少的! 一.简介 UIKitk框架提供一系列的Class(类)来建立和管理iPhone OS应用程序的用户界面接口.应 ...
- iOS学习32之UIKit框架-可视化编程-XIB
1. Interface Builder 可视化编程 1> 概述 GUI : 图形用户界面(Graphical User Interface, 简称GUI, 又称图形化界面) 是指采用图形方式显 ...
- 基础框架Fundation和UIkit框架的定义和使用
Foundation 框架为所有应用程序提供基本的系统服务 您的应用程序以及 UIKit 和其他框架,都建立在 Foundation 框架的基础结构之上.Foundation 框架提供许多基本的对象类 ...
- iOS开发概述UIkit动力学,讲述UIKit的Dynamic特性,UIkit动力学是UIkit框架中模拟真实世界的一些特性。
转发:http://my.oschina.net/u/1378445/blog/335014 iOS UIKit动力学 Dynamics UIAttachmentBehavior 实现iMessage ...
- iOS开发UIKit框架-可视化编程-XIB
1. Interface Builder 可视化编程 1> 概述 GUI : 图形用户界面(Graphical User Interface, 简称GUI, 又称图形化界面) 是指采用图形方式显 ...
- 79、iOS 的Cocoa框架、Foundation框架以及UIKit框架
Cocoa框架是iOS应用程序的基础 1. Cocoa是什么? Cocoa是 OS X和ios 操作系统的程序的运行环境. 是什么因素使一个程序成为Cocoa程序呢?不是编程语言,因为在Cocoa开发 ...
- UIKit 框架之UIView二
下面这些都是UIView一些基本的东西,具体的可以参考UIKit 框架之UIView一博客 一.自定义一个View // // MyView.m // UIView // // Created by ...
- UIKit 框架之Bar、Controller
UIKit框架中有各种Bar,UITabBar.UINavigationBar.UIToolbar.Bar对应的就有一些Item,tabBarItem.navigationItem.toolbarIt ...
随机推荐
- zigbee学习之路(六):Time3(查询方式)
一.前言 通过上次的学习,相信大家对cc2530单片机的定时器的使用有了一定的了解,今天我们来介绍定时器3的使用,为什么介绍定时器3呢,因为它和定时器4功能是差不多的,所以学会定时器3,就基本掌握了c ...
- noi 9265 取数游戏
题目链接:http://noi.openjudge.cn/ch0206/9265/ 题意:从自然数1到N中不取相邻2数地取走任意个数,问方案数. 解法:f[i][1]表示在前i个数中选了第i个的方案数 ...
- 【leetcode❤python】 28. Implement strStr()
#-*- coding: UTF-8 -*- #题意:大海捞刀,在长字符串中找出短字符串#AC源码:滑动窗口双指针的方法class Solution(object): def strStr(se ...
- SQL Server 查询表的记录数(3种方法,推荐第一种)
http://blog.csdn.net/smahorse/article/details/8156483 --SQL Server 查询表的记录数 --one: 使用系统表. SELECT obje ...
- [Oracle] SQL*Loader 详细使用教程(2)- 命令行参数
sqlldr工具 SQL*Loader的客户端工具是sqlldr,在操作系统的命令行下输入sqlldr,后面不接任何参数,将显示帮助信息如下所示(所有命令行参数的简单描述及其默认值),所以你并不需 ...
- python成长之路【第五篇】:python字符编码
在2.7环境中我们要写上这一行#-*- coding:utf-8 -*- 为什么我们要加这一行呢?这一样的意思是置顶编码类型为utf-8编码! 首先在看这个问题之前,咱们是否曾想过一个问题? 为什么我 ...
- springMVC的两种下载方式
1:通过httpServletResponse对象实现下载,觉得LOW的自行跳过 2:有人觉得既然使用的是MVC就要使用spring的方式
- 项目打包文件build.xml
Make命令其实就是一个项目管理工具,而Ant所实现功能与此类似.像make,gnumake和nmake这些编译工具都有一定的缺陷,但是Ant却克服了这些工具的缺陷.最初Ant开发者在开发跨平台的应用 ...
- 手机号 和 email 的正则匹配
手机号 /^1[3|4|5|8] \d{9}$/ email /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/
- Android 如何解决数据库多线程锁的问题
防止多个线程又是读取又是写入 网上找到的方法: 对于这样的问题,解决的办法就是keep single sqlite connection,保持单个SqliteOpenHelper实例,同时对所有数据库 ...