Class
UICollectionViewFlowLayout
--A concrete layout object that organizes items into a grid with optional header and footer views for each section.
提供一个具体的布局对象,用于把section中的item组织成网格式布局,可选头部和底部视图。
Declaration --声明
class UICollectionViewFlowLayout : UICollectionViewLayout -- 继承于UICollectionViewLayout
Overview -- 概览
--The items in the collection view flow from one row or column (depending on the scrolling direction) to the next, with each row comprising as many cells as will fit. Cells can be the same sizes or different sizes.
collection view中的每一行(或列)的items流向下一行(或列),并且每一行的都填满尽可能多的cell,cell的尺寸可以任意。
--A flow layout works with the collection view’s delegate object to determine the size of items, headers, and footers in each section and grid. That delegate object must conform to the
UICollectionViewDelegateFlowLayout
protocol.flow对象需要与
UICollectionViewDelegateFlowLayout
协议的对象一起工作,来决定每个items的尺寸。--Use of the delegate allows you to adjust layout information dynamically. For example, you would need to use a delegate object to specify different sizes for items in the grid. If you do not provide a delegate, the flow layout uses the default values you set using the properties of this class.
如果你不提供delegate,那么flow layout将使用默认值。
--Flow layouts lay out their content using a fixed distance in one direction and a scrollable distance in the other. For example, in a vertically scrolling grid, the width of the grid content is constrained to the width of the corresponding collection view while the height of the content adjusts dynamically to match the number of sections and items in the grid.The layout is configured to scroll vertically by default but you can configure the scrolling direction using the
scrollDirection
property.flow layout布局时,一个方向的长度是固定的,另一个方向的量度是动态的。例如垂直方向 高度 动态,水平方向 宽度 固定。默认是垂直滑动的,即是水平固定。可以通过flow layout的
scrollDirection
属性进行修改滑动方向。--Each section in a flow layout can have its own custom header and footer. To configure the header or footer for a view, you must configure the size of the header or footer to be non zero. You can do this by implementing the appropriate delegate methods or by assigning appropriate values to the
headerReferenceSize
andfooterReferenceSize
properties. If the header or footer size is 0, the corresponding view is not added to the collection view.可以通过delegate或者属性的方式设置页眉页脚视图。
Topics -- 专题
Configuring the Flow Layout -- 配置flow layout,协议
protocol UICollectionViewDelegateFlowLayout
--协议:几乎都要,提供处理布局的方法--The
UICollectionViewDelegateFlowLayout
protocol defines methods that let you coordinate with aUICollectionViewFlowLayout
object to implement a grid-based layout. The methods of this protocol define the size of items and the spacing between items in the grid.该协议主要用于确定items的尺寸和间距
Configuring the Scroll Direction -- 配置滑动的方向
var scrollDirection: UICollectionView.ScrollDirection
--属性:确定网格滑动的方向
Configuring the Item Spacing -- 配置items的间距
var minimumLineSpacing: CGFloat
--属性:网格行之间的最小间距--The minimum spacing to use between lines of items in the grid.
var minimumInteritemSpacing: CGFloat
--属性:行内之间items的最小间距--The minimum spacing to use between items in the same row.
var itemSize: CGSize
--属性:cell的尺寸itemsize--The default size to use for cells.
var estimatedItemSize: CGSize
--属性:cell的估算尺寸--Specifying an estimate value lets the collection view defer some of the calculations needed to determine the actual size of its content.
指定cell的估算尺寸,可以提前获知cell的尺寸,可以优化某些“预先加载‘的算法。例如还没出现在屏幕上的cell。
var sectionInset: UIEdgeInsets
--属性:section的内容的页边距The margins used to lay out content in a section
var sectionInsetReference: UICollectionViewFlowLayout.SectionInsetReference
--属性:安全区域,刘海屏的相关属性
enum UICollectionViewFlowLayout.SectionInsetReference
--属性:安全区域,刘海屏的相关属性
Configuring the Supplementary Views -- 配置额外视图,页眉页脚
var headerReferenceSize: CGSize
--属性:页眉尺寸The default sizes to use for section headers.
var footerReferenceSize: CGSize
--属性:页脚尺寸The default sizes to use for section footers.
Pinning Headers and Footers -- 钉住页眉页脚
var sectionHeadersPinToVisibleBounds: Bool
--属性:断定是否钉住页眉A Boolean value indicating whether headers pin to the top of the collection view bounds during scrolling.
var sectionFootersPinToVisibleBounds: Bool
--属性:断定是否钉住页脚A Boolean value indicating whether footers pin to the bottom of the collection view bounds during scrolling.
Constants -- 一些常量
enum UICollectionView.ScrollDirection
--枚举:确定滑动方向的枚举值Constants indicating the direction of scrolling for the layout.
Flow Layout Supplementary Views --静态常量:可以“使用流布局的”附加视图“的种类”
Constants that specify the types of supplementary views that can be presented using a flow layout.
class let automaticSize: CGSize
--静态常量:文档没说是干嘛的
再看一个协议 UICollectionViewDelegateFlowLayout
Protocol
UICollectionViewDelegateFlowLayout
Inherits From
UICollectionViewDelegate --
继承于UICollectionViewDelegate
--The
UICollectionViewDelegateFlowLayout
protocol defines methods that let you coordinate with aUICollectionViewFlowLayout
object to implement a grid-based layout. The methods of this protocol define the size of items and the spacing between items in the grid.这个协议主要是确定items之间的间距 和 items的大小。
Declaration -- 声明
protocol UICollectionViewDelegateFlowLayout
Overview -- 概览
--All of the methods in this protocol are optional. If you do not implement a particular method, the flow layout delegate uses values in its own properties for the appropriate spacing information.
这个协议里的所有方法都是可选的。如果你不实现这个协议里的方法,那么flow layout 自己也有一些相关的属性默认值来代替这些方法的作用。
--The flow layout object expects the collection view’s delegate object to adopt this protocol. Therefore, implement this protocol on object assigned to your collection view’s
delegate
property.该协议的遵循对象是赋值给collection view的delegate属性的。
Topics -- 专题
Getting the Size of Items -- 获取items的size
func collectionView(UICollectionView, layout: UICollectionViewLayout, sizeForItemAt: IndexPath) -> CGSize
--方法:设置每个items的size-- Asks the delegate for the size of the specified item’s cell.
Getting the Section Spacing -- 获取section的间距
func collectionView(UICollectionView, layout: UICollectionViewLayout, insetForSectionAt: Int) -> UIEdgeInsets
--方法:设置某section的内容的页边距--Asks the delegate for the margins to apply to content in the specified section.
func collectionView(UICollectionView, layout: UICollectionViewLayout, minimumLineSpacingForSectionAt: Int) -> CGFloat
--方法:设置连续行或者列之间的间距--Asks the delegate for the spacing between successive rows or columns of a section.
func collectionView(UICollectionView, layout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt: Int) -> CGFloat
--方法:设置某section中连续items之间的间距--Asks the delegate for the spacing between successive items in the rows or columns of a section.
Getting the Header and Footer Sizes -- 获取页眉页脚尺寸
func collectionView(UICollectionView, layout: UICollectionViewLayout, referenceSizeForHeaderInSection: Int) -> CGSize
--方法:设置某section的页眉尺寸--Asks the delegate for the size of the header view in the specified section.
func collectionView(UICollectionView, layout: UICollectionViewLayout, referenceSizeForFooterInSection: Int) -> CGSize
--方法:设置某section的页脚尺寸Asks the delegate for the size of the footer view in the specified section.