您现在的位置: IOS教程網 >> IOS系統 >  >> iOS 訊息 >> iOS 相關資訊

iOS UICollectionViewController 核心概念解析

編輯:iOS 相關資訊

1. What

The UICollectionViewController class represents a view controller whose content consists of a collection view.

The UICollectionView class manages an ordered collection of data items and presents them using customizable layouts.

 

2. Why

Collection views provide the same general function as table views except that a collection view is able to support more than just single-column layouts. Collection views support customizable layouts that can be used to implement multi-column grids, tiled layouts, circular layouts, and many more. You can even change the layout of a collection view dynamically if you want.

 

3. How

3.1 UICollectionViewLayout(描述 CollectionView 的布局信息)

The job of a layout object is to determine the placement of cells, supplementary views, and decoration views inside the collection view’s bounds and to report that information to the collection view when asked. The collection view then applies the provided layout information to the corresponding views so that they can be presented onscreen.

 

Collection views have three types of visual elements that need to be laid out:

  • Cells are the main elements positioned by the layout. Each cell represents a single data item in the collection. A collection view can have a single group of cells or it can divide those cells into multiple sections. The layout object’s main job is to arrange the cells in the collection view’s content area.

  • Supplementary views present data but are different than cells. Unlike cells, supplementary views cannot be selected by the user. Instead, you use supplementary views to implement things like header and footer views for a given section or for the entire collection view. Supplementary views are optional and their use and placement is defined by the layout object.

  • Decoration views are visual adornments that cannot be selected and are not inherently tied to the data of the collection view. Decoration views are another type of supplementary view. Like supplementary views, they are optional and their use and placement is defined by the layout object.

    Methods to Override(Required)//參照文件

    Optimizing Layout Performance Using Invalidation Contexts //參照文件

    3.2 UICollectionViewCell(組成 CollectionView 的 item)

    A UICollectionViewCell object presents the content for a single data item when that item is within the collection view’s visible bounds.

    類似 UITableViewCell。

    綜上所述,UITableView 能描繪的視覺效果,UICollectionView 都能描繪,而且更加豐富。至於開發時的選擇,還是根據實際場景和要求來決定。

  1. 上一篇文章:
  2. 下一篇文章:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © IOS教程網 All Rights Reserved