1022 -- iOS之UICollectionView类

UICollectionView

--An object that manages an ordered collection of data items and presents them using customizable layouts.

  一个管理一组 有序的 数据的 集合 的对象,而且你可以在这个对象中自定义集合中的 数据对象的 布局。

Declaration

class UICollectionView : UIScrollView  //继承于UIScorllView

Overview  -- 概览

Figure 1

--A collection view using the flow layout

   一个conllection view 可以定义下面这种效果的视图

A collection view using the flow layout
图片来源苹果官网

 

--The collection view gets its data from the data source object, which is an object that conforms to the UICollectionViewDataSource Protocol and is provided by your app.

     对你来讲,管理一个collection view 最主要的就是管理它里面的那些数据,因此你的 collection view 对象要有一个遵循了UICollectionViewDataSource Protocol协议的对象,用来储存数据,一般来说,collection view 直接遵循该协议也是可以的。

--Data in the collection view is organized into individual items, which can then be grouped into sections for presentation.

    collection view 中的数据是单独成每一项进行管理的,然后再把每一项单独的数据组织成一节来展示。一项数据是展示的最小组织单元。

--The collection view presents items onscreen using a cell, which is an instance of the UICollectionViewCell class that your data source configures and provides.

    collection view 使用 单元格cell 来展示单独的一项数据,★ cell是UICollectionViewCell 类的实例,你要做的是用每一项单独的数据来配置每一个cell 。

--These supplementary views can be things like section headers and footers that are separate from the individual cells but still convey some sort of information. Support for supplementary views is optional and defined by the collection view’s layout object, which is also responsible for defining the placement of those views.

    除了主要用cell视图来展示每一项数据外,collection 也提供了一些额外视图来展示一些额外的数据。例如每一节的页眉页脚视图,这些页眉页脚视图是可选的,页眉页脚视图是通过collection view 的 layout object 对象来定义它们的位置的。

--Besides embedding it in your user interface, you use the methods of UICollectionView object to ensure that the visual presentation of items matches the order in your data source object. Thus, whenever you add, delete, or rearrange data in your collection, you use the methods of this class to insert, delete, and rearrange the corresponding cells. You also use the collection view object to manage the selected items, although for this behavior the collection view works with its associated delegate object.

    你可以用UICollectionView 实例的方法来匹配 数据源中每一项数据 的对应顺序,也可以进行相应的增删改查、重排序。你可以使用 委托对象 的方法来管理已经被选中了的某一项cell,所以,你的collection view 要遵循委托协议,或者有一个委托对象。一般都是collection view 直接 遵循UICollectionViewDelegate协议。用其他来源的委托对象我现在还没有思路。

 

Collection Views and Layout Objects  -- 相关的布局对象

 

--A very important object associated with a collection view is the layout object, which is a subclass of the UICollectionViewLayout class. Although it defines their locations, the layout object does not actually apply that information to the corresponding views. Because the creation of cells and supplementary views involves coordination between the collection view and your data source object, the collection view actually applies layout information to the views. Thus, in a sense, the layout object is like another data source, only providing visual information instead of item data.

      collection view 需要一个子类化了UICollectionViewLayout 的实例,这个实例仅仅用于提供可视化的一些相关的布局信息,并不是设计来提供数据给cell 管理的。因为“cell和额外视图的创建”需要 数据源对象与collection view 进行协调,所以是由collection view 来运用这些布局信息的,而不是直接由UICollectionViewLayout 来运用这些布局信息的。

 

--You normally specify a layout object when creating a collection view but you can also change the layout of a collection view dynamically. The layout object is stored in the collectionViewLayout property. Setting this property directly updates the layout immediately, without animating the changes. If you want to animate the changes, you must call the setCollectionViewLayout(_:animated:completion:) method instead.

      你可以在创建collection view 的时候设置一个layout 对象,也可以动态的设置layout 对象。动态设置是指,你直接给collection view的collectionViewLayout属性赋值,赋值之后,collection view 立即更新视图的布局,但是没有动画效果。如果你想要动画效果的话,那就不要直接赋值,而是通过调用collection view 的setCollectionViewLayout(_:animated:completion:)方法来更新布局。

 

--If you want to create an interactive transition—one that is driven by a gesture recognizer or touch events—use the startInteractiveTransition(to:completion:) method to change the layout object. That method installs an intermediate layout object whose purpose is to work with your gesture recognizer or event-handling code to track the transition progress. When your event-handling code determines that the transition is finished, it calls the finishInteractiveTransition() or cancelInteractiveTransition() method to remove the intermediate layout object and install the intended target layout object.

     如果你想创建一个互动式的视图转换,就是客户可以通过手势来修改视图布局。那你可以通过collection view 的startInteractiveTransition(to:completion:) 方法来更改collection view 的layout 对象。这个方法会内建一个临时layout 对象,临时layout对象会根据‘手势识别器“或者”事件响应代码“来跟踪视图转换的进程。当手势完成之后,或者事件响应完之后,事件响应代码会通过调用 collection view 的inishInteractiveTransition() or cancelInteractiveTransition() 方法来删除临时layout对象,然后再安装一个目标layout对象给collection view。

 

Creating Cells and Supplementary Views  -- 创建cell 和额外视图

--The collection view’s data source object provides both the content for items and the views used to present that content. When the collection view first loads its content, it asks its data source to provide a view for each visible item. To simplify the creation process for your code, the collection view requires that you always dequeue views, rather than create them explicitly in your code. There are two methods for dequeueing views. The one you use depends on which type of view has been requested:

    collection view 的“数据源对象”既提供每一项独立数据内容,也提供view 的内容。当collection view 加载内容的时候,是请求数据源对象提供数据信息的。但是你不应该在代码中直接就创建视图对象cell,而是先通过调用collection view 的出队列方法来提供 你定义的视图对象cell,然后没有的话再创建视图对象cell,这样起到复用的效果。

        创建cell视图对象的时候调用的出队列方法是 dequeueReusableCell(withReuseIdentifier:for:)

        创建额外视图对象调用的出队列方法是 dequeueReusableSupplementaryView(ofKind:withReuseIdentifier:for:)

 

--Before you call either of these methods, you must tell the collection view how to create the corresponding view if one does not already exist. For this, you must register either a class or a nib file with the collection view. For example, when registering cells, you use the register(_:forCellWithReuseIdentifier:) or register(_:forCellWithReuseIdentifier:) method. As part of the registration process, you specify the reuse identifier that identifies the purpose of the view. This is the same string you use when dequeueing the view later.

     在调用上面两个方法创建cell之前,你必须先告诉collection view 当队列中不存在指定id的视图的时候,该如何创建这些视图对象,cell本身也是一个视图对象。所以,你还要注册cell对象,然后还要指定cell的id。在collection view 里注册cell是通过调用该collection view 的register(_:forCellWithReuseIdentifier:) or register(_:forCellWithReuseIdentifier:) 方法来注册的。

 

--After dequeueing the appropriate view in your delegate method, configure its content and return it to the collection view for use. After getting the layout information from the layout object, the collection view applies it to the view and displays it.

    是用委托对象中的方法出队列cell吗?委托对象不直接就是cell了吗?不是,cell是一个“一项独立数据对应的”视图对象。哎,好吧,在  ”委托协议的方法体中“ 调用 “collection view 的出队列方法”  出队你的cell之后,你要配置该cell的视图内容,并且把cell返回给collection view 使用。

     也就是无论你是通过注册获取到cell ,还是通过出队列获取到cell,在你获取到cell之后,你就对这个cell 进行视图内容配置,在委托协议的方法体获取这个cell,返回值这个cell,这样系统就默认把这个cell分配给collection view了。collection view 会自动根据layout 对象里的信息对cell进行布局?是的。layout对象可以在collection view 的构造方法中传递进去。

--For more information about implementing the data source methods to create and configure views, see UICollectionViewDataSource.

     更多关于,为了配置view而需要去实现的data source 里的方法,请看超链接。

 

Reordering Items Interactively  -- 交互式重排序每一条目

 

--Collection views allow you to move items around based on user interactions. Normally, the order of items in a collection view is defined by your data source. If you support the ability for users to reorder items, you can configure a gesture recognizer to track the user’s interactions with a collection view item and update that item’s position.

   通常,collection view 里的单元格顺序是由数据源对象决定的,但是你可以配置一个手势识别器来跟踪用户拖动 collection view的一个单元格的轨道,然后更新这个单元格的位置。

 

--To begin the interactive repositioning of an item, call the beginInteractiveMovementForItem(at:) method of the collection view. While your gesture recognizer is tracking touch events, call the updateInteractiveMovementTargetPosition(_:) method to report changes in the touch location. When you are done tracking the gesture, call the endInteractiveMovement() or cancelInteractiveMovement() method to conclude the interactions and update the collection view.

     collection view 会自动调用collection view 的beginInteractiveMovementForItem(at:) 方法来开始 通过客户的交互手势 来重定位单元格。在手势识别器跟踪触摸事件期间,collection view 会调用自己的updateInteractiveMovementTargetPosition(_:) 方法来实时报告当前的触摸位置。当手势操作结束时,collection view 会自动调用自己的endInteractiveMovement() or cancelInteractiveMovement() 方法,所以你可以在这两个方法里确定cell的最终位置。

 

--During user interactions, the collection view invalidates its layout dynamically to reflect the current position of the item. If you do nothing, the default layout behavior repositions the items for you, but you can customize the layout animations if you want. When interactions finish, updates its data source object with the new location of the item.

    在客户交互期间,collection view 会无效化自动布局,这样是为了映射出单元格的当前位置。如果你什么也不做,collection view默认的布局行为会帮你重定位单元格,你也可以自定义布局动画效果。当用户交互完成后,collection view 会更新数据源对象,然后重定位单元格的位置。

--The UICollectionViewController class provides a default gesture recognizer that you can use to rearrange items in its managed collection view. To install this gesture recognizer, set the installsStandardGestureForInteractiveMovement property of the collection view controller to true.

     UICollectionViewController类提供了默认的手势识别器给你使用,所以你可以使用该手势识别器重排序你的单元格。如果你要安装这个手势识别器,那么需要把collection view 的installsStandardGestureForInteractiveMovement属性设置为true。

 

Interface Builder Attributes  -- 界面建造器中的属性

Table 1

Collection view attributes

Attribute

Description

Items

--The number of prototype cells. This property controls the specified number of prototype cells for you to configure in your storyboard.

    collection view 的items 属性表示的是cells 原型的数量,你可以用items属性来设置cell的数量。

Layout

--Use this control to select between the UICollectionViewFlowLayout object and a custom layout object that you define.When the flow layout is selected, you can also configure the scrolling direction for the collection view’s content and whether the flow layout has header and footer views.

    这个属性代表的是布局的控件,你可以使用这个控件来选择 UICollectionViewFlowLayout 对象或者你自定义的布局对象。当流布局对象被选中时,无论有没有页眉页脚视图,你都可以配置滑动的方向。

--When a custom layout is selected, you must specify the UICollectionViewLayout subclass to use.

   如果你选择的是自定义布局对象,那么它必须是UICollectionViewLayout的子类

--When the Flow layout is selected, the Size inspector for the collection view contains additional attributes for configuring flow layout metrics. Use those attributes to configure the size of your cells, the size of headers and footers, the minimum spacing between cells, and any margins around each section of cells. For more information about the meaning of the flow layout metrics, see UICollectionViewFlowLayout.

    当流布局对象被选定的时候,collection view 的尺寸检查器就包含了“配置流布局对象度量“的附加属性。使用这些附加属性,你可以配置cell的大小、页眉页脚的大小、cell 之间的间距、以及不同section中的cell之间的间距。更多关于流对象度量的信息,参考超链接。

 

Internationalization  --   国际化版本配置

--A collection view has no direct content of its own to internationalize. Instead, you internationalize the cells and reusable views of the collection view. For more information about internationalization, see Internationalization and Localization Guide.

参考超链接

Accessibility  --  设备辅助功能

For general information about making your interface accessible, see Accessibility Programming Guide for iOS.

参考超链接

 

官网给出的属性和方法:

 

Initializing a Collection View  --  构造collection view

init(frame: CGRect, collectionViewLayout: UICollectionViewLayout)

      --Initializes and returns a newly allocated collection view object with the specified frame and layout.

         用指定的边框和布局来初始化一个collection view 并返回。

init?(coder: NSCoder)

         必要初始化器,是storyboard需要调用来初始化界面的,人工代码界面不要管,代码提示添加就添加好了。

 

Providing the Collection View Data  --  给collection view 提供视图相关的数据

 

var dataSource: UICollectionViewDataSource?     //属性:数据源对象。

     --通过该属性设置或获取collection view 的数据源对象。

       

protocol UICollectionViewDataSource     //协议:数据源对象必须遵循的协议

    -- A data source object represents your app’s data model and vends information to the collection view as needed.

         这个既不是UICollectionView的属性,也不是方法。只是说UICollectionView的dataSource属性必须遵循UICollectionViewDataSource协议,遵循该协议之后,dataSource对象就负责提供数据给collection view使用,这些数据用于展cell和页眉页脚的视图内容。

 

protocol UICollectionViewDataSourcePrefetching。 //协议:数据源对象可以遵循的协议

     --A protocol that provides advance warning of the data requirements for a collection view, allowing the triggering of asynchronous data load operations.

        该协议允许数据源对象的数据进行异步加载,也提供了数据到来时发出预先提醒的功能。       

 

Managing Collection View Interactions   --管理collection view 的交互

 

var delegate: UICollectionViewDelegate?          //属性:委托对象

     --就是一个委托对象,负责管理collection view 的行为。或者说提供行为的方法给你使用。

      

protocol UICollectionViewDelegate         //协议:委托对象必须遵循的协议

     --The UICollectionViewDelegate protocol defines methods that allow you to manage the selection and highlighting of items in a collection view and to perform actions on those items. The methods of this protocol are all optional.

      这个协议里的方法都是可选的来实现,管理cell的选择,高亮,还有动作这些行为。

 

Configuring the Background View  --  配置collection view 的背景视图

 

var backgroundView: UIView?       //属性:背景视图对象

        --赋值该属性,提供背景视图对象给collection view 使用

 

Prefetching Collection View Cells and Data  --  预先抓取collection view 的cell和数据

 

--UICollectionView provides two prefetching techniques you can use to improve responsiveness:

  UICollectionView默认提供了两种预先抓取机制来提高collection view 的流畅性。

  • Cell prefetching When a collection view requires a large number of cells simultaneously—for example, a new row of cells in grid layout—the cells are requested earlier than the time required for display. Cell rendering is therefore spread across multiple layout passes, resulting in a smoother scrolling experience. Cell prefetching is enabled by default.

             cell的提前抓取机制,当同一时间需要大量的cell时,而且这些情况是可以预知时候,UICollectionView类默认提供了预先抓取的功能。例如在网格视图中预先加载下一行的每一个cell。

  • Data prefetching provides a mechanism whereby you are notified of the data requirements of a collection view in advance of the requests for cells. Assign an object that conforms to the UICollectionViewDataSourcePrefetching protocol to the prefetchDataSource property to receive notifications of when to prefetch data for cells.

  • 数据提前抓取机制,在该机制下,你可以在cell请求数据之前 被通知到数据的需求是什么,因而你就可以预先准备数据了。例如别人通过网路访问你的数据时,你可以预先准备好数据。所以UICollectionView类的prefetchDataSource属性必须遵循UICollectionViewDataSourcePrefetching协议,才可以使用该机制。

 

var isPrefetchingEnabled: Bool       //属性:使能预先抓取机制

     --Denotes whether cell and data prefetching are enabled.

        设置该属性表明是否使用预先抓取机制。

var prefetchDataSource: UICollectionViewDataSourcePrefetching?       //属性:用于预先抓取的数据源对象

     --The object that acts as the prefetching data source for the collection view, receiving notifications of upcoming cell data requirements.

       这个属性用于储存预先抓取的数据,接收系统预先抓取的通知。

 

Creating Collection View Cells  --  创建collection view 的cell视图

 

func register(AnyClass?, forCellWithReuseIdentifier: String)      //方法:注册cell视图

    --Register a class for use in creating new collection view cells.

       使用该方法为collection view注册一个cell,参数是cell对象。先注册,才可以使用。

func register(UINib?, forCellWithReuseIdentifier: String)      //方法:用nib file方式注册cell视图

    --Register a nib file for use in creating new collection view cells.

       使用该方法是从nib file中获取cell视图来注册

func register(AnyClass?, forSupplementaryViewOfKind: String, withReuseIdentifier: String)

                                                                                                                                    //方法:注册页眉页脚视图

func register(UINib?, forSupplementaryViewOfKind: String, withReuseIdentifier: String)

                                                                                                                                    //方法:通过nib file注册页眉页脚视图

func dequeueReusableCell(withReuseIdentifier: String, for: IndexPath) -> UICollectionViewCell

                                                                                                                                   //方法:返回可重用的cell对象。

      --Returns a reusable cell object located by its identifier                    

       你可以调用该方法,返回一个可重用的cell对象,cell根据你设置的id进行重用。

func dequeueReusableSupplementaryView(ofKind: String, withReuseIdentifier: String, for: IndexPath) -> UICollectionReusableView                                             //方法:返回可以重用的页眉页脚视图对象。

     --Returns a reusable supplementary view located by its identifier and kind.

 

Changing the Layout   -- 修改collection view 的布局

var collectionViewLayout: UICollectionViewLayout    //属性:设置或获取布局对象

     --The layout used to organize the collected view’s items.

        布局对象用于组织collection view每一项的布局

func setCollectionViewLayout(UICollectionViewLayout, animated: Bool)   //属性:设置布局对象。

     --Changes the collection view’s layout and optionally animates the change.

         可以通过该方法设置collection view 的布局对象来修改布局,可选动画效果

func setCollectionViewLayout(UICollectionViewLayout, animated: Bool, completion: ((Bool) -> Void)?)

                                                                                                                             //方法:设置布局对象并告知完成布局

    --Changes the collection view’s layout and notifies you when the animations complete.

       你可以在参数的闭包内敲写你的代码,在布局完成之后,这个闭包代码就会执行。

func startInteractiveTransition(to: UICollectionViewLayout, completion: UICollectionView.LayoutInteractiveTransitionCompletion?) -> UICollectionViewTransitionLayout

                                                                                                                             //方法:互动式改变布局

    --Changes the collection view’s current layout using an interactive transition effect.

        调用该方法,使用互动式的过渡转换效果来修改当前的布局,都是通过传参的方式,提供信息给UICollectionView

 

func finishInteractiveTransition()                      //方法:告知互动式转换视图已经完成

    --Tells the collection view to finish an interactive transition by installing the intended target layout.

        调用该方法后,UICollectionView会移除临时的视图布局对象,安装最终的布局视图对象。“临时转换对象”是客户“手势滑动时”临时搭建的布局对象,用于展示当前布局的变化效果。

func cancelInteractiveTransition()                  //方法:取消互动式视图转换(变形)

    --Tells the collection view to abort an interactive transition and return to its original layout object.

         你可以调用该方法来跟UICollectionView说,取消客户刚刚手势滑动的布局。代码层面的视觉是,移除临时布局对象,重新安装原先的布局对象。

 

Customizing Collection View Layouts(实例代码)     //实例代码:关于如何自定义collection view 的布局。

    --Customize a view layout by changing the size of cells in the flow or implementing a mosaic style.

 

Getting the State of the Collection View  --  获取collection view 的状态

 

var numberOfSections: Int                                                               //计算型属性:返回collection view的section个数

    --Returns the number of sections displayed by the collection view.

func numberOfItems(inSection: Int) -> Int                          //方法:返回某section中item的个数

    --Returns the number of items in the specified section.

var visibleCells: [UICollectionViewCell]                               //计算型属性:返回当前可见的items的数组

    --Returns an array of visible cells currently displayed by the collection view.

 

Inserting, Moving, and Deleting Items  --  插入、移动、删除items

func insertItems(at: [IndexPath])                                                   //方法:在某索引位置插入新的item

    --Inserts new items at the specified index paths.

func moveItem(at: IndexPath, to: IndexPath)                              //方法:将某索引位置的item移动到另一个索引位置

    --Moves an item from one location to another in the collection view.

func deleteItems(at: [IndexPath])                                                   //方法:删除某索引位置的item

    --Deletes the items at the specified index paths.

 

Inserting, Moving, and Deleting Sections    --  插入、移动、删除sections

func insertSections(IndexSet)                                                           //方法:在某索引位置插入新的section

    --Inserts new sections at the specified indexes.

func moveSection(Int, toSection: Int)                                   //方法:将某section移动到某位置

    --Moves a section from one location to another in the collection view.

func deleteSections(IndexSet)                                           //方法:删除某位置的section

    --Deletes the sections at the specified indexes.

 

Reordering Items Interactively    --  互动式地重排序item

 

func beginInteractiveMovementForItem(at: IndexPath) -> Bool           //方法:告知开始某item的交互

    --Initiates the interactive movement of the item at the specified index path.

       返回ture的话,说明collection view 可以开启在某索引位置item的交互式移动,一般是在“手势识别器的“方法代码中调用该方法进行判断能否移动。

func updateInteractiveMovementTargetPosition(CGPoint)         //方法:用参数更新边界内部的items的位置

    --Updates the position of the item within the collection view’s bounds.

        通过传入的坐标参数,更新当前item需要移动到的位置,这个应该是给手势识别器实时调用的

func endInteractiveMovement()                                                       //方法:告知已经完成了交互式移动

    --Ends interactive movement tracking and moves the target item to its new location.

       你调用该方法告知collection view 已经完成交互式移动了,让它做移除临时布局对象等手尾。这里是移动,之前是转换,就是放大缩小那些,可能翻译成变形更好一些。

func cancelInteractiveMovement()                                        //方法:取消交互式移动

     --Ends interactive movement tracking and returns the target item to its original location.

 

Managing Drag Interactions  --  管理拖曳的交互动作

 

var dragDelegate: UICollectionViewDragDelegate?       //属性:设置或获取collection view 的“拖曳委托对象”

      --The delegate object that manages the dragging of items from the collection view.

         拖曳委托对象的工作主要是管理拖曳collection view 中的item

protocol UICollectionViewDragDelegate                            //协议:拖曳委托对象必须遵循的协议

      --The interface for initiating drags from a collection view.

          好吧,拖曳行为用另外一种协议进行管理

var hasActiveDrag: Bool                                                           //属性:告知是否正在拖曳

     --A Boolean value indicating whether items were lifted from the collection view and have not yet been dropped.

        就是告知现在有没有item正在被拖曳,而且该item还没被删除

var dragInteractionEnabled: Bool                             //属性:使能拖曳交互

     --A Boolean value indicating whether the collection view supports drags and drops between apps.

       这个居然可以将一个cell从一个app拖曳到另一个app,这么神奇吗?我还没用过

 

Managing Drop Interactions  --  管理拖之后的放下动作的交互

  所以这个是拖曳之后的放下动作,之前只是单纯地拖曳?

var dropDelegate: UICollectionViewDropDelegate?          //属性:放下动作的委托对象

    --The delegate object that manages the dropping of items into the collection view.

     

var hasActiveDrop: Bool                                          //属性:表明现在的交互对话是否是可拖放的

    --A Boolean value indicating whether the collection view is currently tracking a drop session.

 

var reorderingCadence: UICollectionView.ReorderingCadence     //属性:设置和获取拖放之后重排序的速度

     --The speed at which items in the collection view are reordered to show potential drop locations.

enum UICollectionView.ReorderingCadence                   //枚举:枚举重排序的速度

     --Constants indicating the speed at which collection view items are reorganized during a drop.

          你可以用这个枚举中的常量来设置,拖放一个item之后,item被重排序的速度

 

Managing the Selection    --  管理item的的选择

 

var allowsSelection: Bool                                            //属性: 设置item是否可被选择

    --A Boolean value that indicates whether users can select items in the collection view.

 

var allowsMultipleSelection: Bool                       //属性:设置是否可以多选item

    --A Boolean value that determines whether users can select more than one item in the collection view.

 

var indexPathsForSelectedItems: [IndexPath]?            //属性:返回 已经选择的item的索引 的数组

    --The index paths for the selected items.

func selectItem(at: IndexPath?, animated: Bool, scrollPosition: UICollectionView.ScrollPosition)

                                                                                                             //方法:选择某索引位置的item

    --Selects the item at the specified index path and optionally scrolls it into view.

         你可以根据手势 调用该方法来设置被选中的item

func deselectItem(at: IndexPath, animated: Bool)             //方法:取消某索引位置的item的选中

    --Deselects the item at the specified index.

 

Managing Focus  --  管理焦点

var remembersLastFocusedIndexPath: Bool                   //属性:是否记住上一次焦点所在的索引位置

    --A Boolean value indicating whether the collection view automatically assigns the focus to the item at the last focused index path.

     设置为true的话,collection view 会自动分配焦点给上次焦点的所在索引位置

 

Locating Items and Views in the Collection View  --  定位collection view中的item和view

 

func indexPathForItem(at: CGPoint) -> IndexPath?             //方法:返回在某坐标点的item 的索引位置

    --Returns the index path of the item at the specified point in the collection view.

var indexPathsForVisibleItems: [IndexPath]                //计算型属性:返回当前可见item的数组

    --An array of the visible items in the collection view.

func indexPath(for: UICollectionViewCell) -> IndexPath?       //方法:返回某cell的索引位置

    --Returns the index path of the specified cell.

func cellForItem(at: IndexPath) -> UICollectionViewCell?     //方法:返回某索引位置的可见的cell

    --Returns the visible cell object at the specified index path.

func indexPathsForVisibleSupplementaryElements(ofKind: String) -> [IndexPath]

                                                                                                                                  //方法:返回某类型的页眉页脚视图的索引数组

    --Returns the index paths of all visible supplementary views of the specified type.

func supplementaryView(forElementKind: String, at: IndexPath) -> UICollectionReusableView?

                                                                                                                             //方法:返回某索引位置的额外视图 

    --Returns the supplementary view at the specified index path.

func visibleSupplementaryViews(ofKind: String) -> [UICollectionReusableView]

                                                                                                                           //方法:返回某类型的额外视图的数组

    --Returns an array of the visible supplementary views of the specified kind.

 

Getting Layout Information  --  获取布局信息

 

func layoutAttributesForItem(at: IndexPath) -> UICollectionViewLayoutAttributes?

                                                                                                          //方法:返回某索引item的布局属性对象

    --Returns the layout information for the item at the specified index path.

func layoutAttributesForSupplementaryElement(ofKind: String, at: IndexPath) -> UICollectionViewLayoutAttributes?                             //方法:返回某索引额外视图的布局信息

    --Returns the layout information for the specified supplementary view.

 

Scrolling an Item Into View  --  滑动一个item进collection view 可视范围里

func scrollToItem(at: IndexPath, at: UICollectionView.ScrollPosition, animated: Bool)

                                                                                                          //方法:设置内视图滑动到某索引的item时可见才停止滑动

    --Scrolls the collection view contents until the specified item is visible. 

 

Animating Multiple Changes to the Collection View  --  动画展示collection view 的多个改变

func performBatchUpdates((() -> Void)?, completion: ((Bool) -> Void)?)

    --Animates multiple insert, delete, reload, and move operations as a group.

       以动画效果展示一组对collection view 的操作,这组操作包括增、删、改、查、重加载

     

Reloading Content  --  重新加载collection view 的内容

var hasUncommittedUpdates: Bool                                                    //计算型属性:判断更新内容是否提交

     --A Boolean value indicating whether the collection view contains drop placeholders or is reordering its items as part of handling a drop.

      一个布尔值,为true时,说明拖放操作的事件还没提交,也就是collection view 里还包含拖放占位符,或者正在拖放。

func reloadData()                                                    //方法:重新加载collection view 的所有数据

     --Reloads all of the data for the collection view.

         调用该方法时,会重新加载collection view的所用属性,一般可以用线程调用。

func reloadSections(IndexSet)                              //方法:重新加载某索引位置的section

     --Reloads the data in the specified sections of the collection view.

func reloadItems(at: [IndexPath])                      //方法:重新加载某索引位置的item

     --Reloads just the items at the specified index paths.

 

Constants  --  相关常量

 

struct UICollectionView.ScrollPosition              //结构体:定义滑动item到视图可视范围的滑动方式

    --Constants that indicate how to scroll an item into the visible portion of the collection view.

typealias UICollectionView.LayoutInteractiveTransitionCompletion          //闭包:表明互动完成后的执行

    --The completion block called at the end of an interactive transition for a collection view.

       当客户转换视图的互动完成之后,会执行这个代码块。

     

Type Properties  --  类型属性(静态属性)

class let elementKindSectionFooter: String        //静态属性:是一个字符串,用于指定页脚的视图类型

class let elementKindSectionHeader: String       //静态属性:是一个字符串,用于指定页头的视图类型

 

Enumerations  --  枚举

enum UICollectionView.ElementCategory              //枚举属性:关于collection view中包含的视图类型的枚举值

    --Constants specifying the type of view.

enum UICollectionView.ScrollDirection

    --Constants indicating the direction of scrolling for the layout.         //枚举属性:关于布局滑动方向的枚举值

 

至此,官网的UICollectionView 的API文档翻译完毕


 

 

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值