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)cellClass
forCellWithReuseIdentifier:(NSString *)identifier  :从一个class文件进行cell(item)的注册

      (2)- (void)registerNib:(UINib *)nib
forCellWithReuseIdentifier:(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 nil.

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 nil.

identifier

The reuse identifier for the specified view. This parameter must not be nil.

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的更多相关文章

  1. Swift - 重写UIKit框架类的init初始化方法(以UITabBarController为例)

    原来写了篇文章讲UITabBarController的用法,当时是从UIViewController跳转到UITabBarController页面,代码如下: 1 self.presentViewCo ...

  2. UIKit框架

    在今后的应用程序构建中,会陆续使用各式各样的控件,因此UIKit框架的引入是必不可少的! 一.简介 UIKitk框架提供一系列的Class(类)来建立和管理iPhone OS应用程序的用户界面接口.应 ...

  3. iOS学习32之UIKit框架-可视化编程-XIB

    1. Interface Builder 可视化编程 1> 概述 GUI : 图形用户界面(Graphical User Interface, 简称GUI, 又称图形化界面) 是指采用图形方式显 ...

  4. 基础框架Fundation和UIkit框架的定义和使用

    Foundation 框架为所有应用程序提供基本的系统服务 您的应用程序以及 UIKit 和其他框架,都建立在 Foundation 框架的基础结构之上.Foundation 框架提供许多基本的对象类 ...

  5. iOS开发概述UIkit动力学,讲述UIKit的Dynamic特性,UIkit动力学是UIkit框架中模拟真实世界的一些特性。

    转发:http://my.oschina.net/u/1378445/blog/335014 iOS UIKit动力学 Dynamics UIAttachmentBehavior 实现iMessage ...

  6. iOS开发UIKit框架-可视化编程-XIB

    1. Interface Builder 可视化编程 1> 概述 GUI : 图形用户界面(Graphical User Interface, 简称GUI, 又称图形化界面) 是指采用图形方式显 ...

  7. 79、iOS 的Cocoa框架、Foundation框架以及UIKit框架

    Cocoa框架是iOS应用程序的基础 1. Cocoa是什么? Cocoa是 OS X和ios 操作系统的程序的运行环境. 是什么因素使一个程序成为Cocoa程序呢?不是编程语言,因为在Cocoa开发 ...

  8. UIKit 框架之UIView二

    下面这些都是UIView一些基本的东西,具体的可以参考UIKit 框架之UIView一博客 一.自定义一个View // // MyView.m // UIView // // Created by ...

  9. UIKit 框架之Bar、Controller

    UIKit框架中有各种Bar,UITabBar.UINavigationBar.UIToolbar.Bar对应的就有一些Item,tabBarItem.navigationItem.toolbarIt ...

随机推荐

  1. PHP延迟静态绑定:static关键字

    PHP5.3中引入了延迟静态绑定的概念.该特性最明显的标志就是新关键字static.static类似于self,但它指的是被调用的类而不是包含类.在本例中,它的意思是调用Document::creat ...

  2. ReactiveCocoa(RAC)

    好处:代码高聚合,方便我们管理: 链式编程: CaculatorMaker.h #import <Foundation/Foundation.h> #define ADD #define ...

  3. 推荐流程设计器http://www.processon.com/

    以前一直用的Rational Rose进行类图,流程设计,最近发现了ProcessOn使用了下,感觉很好用,相比rose 1.有中文说明,rose全专业英文,理解起来比较费劲: 2.直线比较直,ros ...

  4. iOS - OC NSStream 文件流

    前言 @interface NSStream : NSObject @interface NSOutputStream : NSStream 1.文件流的使用 NSString *filePath = ...

  5. 学习mongo系列(十一)关系

    准备工作:首先在maxh数据库的address集合中先插入数据 > db.address.insert({child_address:"gansu"}) WriteResul ...

  6. js之oop <三>属性标签

    读取属性标签 获取对象属性标签,用 Object.getOwnPropertyDescriptor方法.getOwnPropertyDescriptor(); 参数:属性所在对象(object),属性 ...

  7. Windows 域(domain)

    http://baike.baidu.com/view/1512519.htm http://baike.baidu.com/view/1218493.htm http://www.jb51.net/ ...

  8. Android SharePreference 在主进程和次进程间共享数据不同步出错

      SharedPreference作为android五大存储(网络,数据库,文件,SharedPreference,contentProvider)之中最方便使用的一个,从类名上来看就不是一个存储大 ...

  9. WEB项目 后台接收前端数组

    //保存区域选择的设备 $scope.saveDevice = function(){ var device = []; $("input[type='checkbox']:checked& ...

  10. 【转】关于 Web GIS

    以下部分选自2015-03-01出版的<Web GIS从基础到开发实践(基于ArcGIS API for JavaScript)>一书中的前言部分: Web GIS 概念于1994 年首次 ...