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. Linux系统软件

    ubuntu系统镜像文件: http://pan.baidu.com/s/1jGGgszO 虚拟机: http://pan.baidu.com/s/1hqrhQQg

  2. sql server中如何查看执行效率不高的语句

    sql server中,如果想知道有哪些语句是执行效率不高的,应该如何查看呢?下面就将为您介绍sql server中如何查看执行效率不高的语句,供您参考.   在测量功能时,先以下命令清除sql se ...

  3. Underscore.js 初探

    一. 简介   Underscore 这个单词的意思是“下划线”.   Underscore.js 是一个 JavaScript 工具库,提供了一整套的辅助方法供你使用.   Think that - ...

  4. Flowplayer-Skin

    SOURCE URL: https://flowplayer.org/docs/skinning.html Skinning with CSS3 Flowplayer skin design is C ...

  5. Duilib 实现窗口点击关闭确认退出提示

    此功能是记住用户的操作,在用户点击关闭时是真退出程序还是最小化到托盘,我们常见的PC客户端都有此功能,例如:IMO客户端.网易云音乐 我自己的项目中也要实现此功能,在此总结一下,最终效果: .h文件 ...

  6. MAC地址泛洪攻击测试

    测试环境:kali系统(2个kali分别作攻击人和目标用户) win7系统(主机) 1.步配置FTP设置用户名密码 2.在攻击kali端测试网络的连通性 3.测试tpf是否正常 开始泛洪 4.开始抓包 ...

  7. 。【自学总结 3】------3ds Max 主工具栏

    1.选择并链接:选择对象,使其和其他对象建立父子关系. 2.断开选择链接:撤销链接关系. 3.选择过滤器列表:可以限制要选择的对象的特定类型和组合.例如,我们选择几何体后,其他对象就无法被选择. 4. ...

  8. UIDatePicker的用法

    目录[-] 1.Locale 2.Calendar 3.timeZone 4.date 5.minimumDate 6.maximumDate 7.countDownDuration 8.minute ...

  9. NGUI Scroll List

    NGUI Scroll List 1.Add GameObject with Script UI Panel(NGUI -> UI -> NGUI Panel) and Script UI ...

  10. 关于OPencv版本不符合,相关库变化问题

    由于OPencv发展迅速,已经省略了很多原来的库文件,奈何自己才疏学浅,所以只能把OPencv 1.0中的相关版本中的库文件一直过去. 链接: http://pan.baidu.com/s/1qY1Z ...