IOS 集合视图指南2:集合视图基础

Collection View Basics(集合视图基础)

To present its content onscreen, a collection view cooperates with many different objects. Some objects are custom and must be provided by your app. For example, your app must provide a data source object that tells the collection view how many items there are to display. Other objects are provided by UIKit and are part of the basic collection view design.

Like tables, collection views are data-oriented objects whose implementation involves a collaboration with your app’s objects. Understanding what you have to do in your code requires a little background information about how a collection view does what it does.

为了在屏幕上展示内容,集合视图要和很多不同的对象协作。一些对象是自定义的,必须由你的应用提供。举个例子,你的应用必须提供数据源告诉集合视图要展示多少个元素。其他对象是UIKit框架提供的作为集合视图的设计基础

和表视图类似,集合视图是数据导向的对象,完成时候设计了你的应用对象之间的协作。理解你要在代码中怎样做,需要了解集合视图的运作方法的知识。

A Collection View Is a Collaboration of Objects(集合视图是对象之间的协作)

The design of collection views separates the data being presented from the way that data is arranged and presented onscreen. Although your app is strictly responsible for managing the data to be presented, its visual presentation is managed by many different objects.Table 1-1lists the collection view classes in UIKit and organizes them by the roles they play in implementing a collection view interface. Most of the classes are designed to be used as is without any need for subclassing, so you can usually implement a collection view with very little code. And when you want to go beyond the provided behavior, you can subclass and provide that behavior

集合视图的设计分开了展示数据和屏幕上呈现的内容。尽管你的应用严格按照数据来展现内容,但是展示的内容由多个不同对象决定。表1.1列出了UIKit中的集合视图类以及他们是如何按照在集合视图界面中扮演的角色来组织他们的。这些类中的大部分被设计成不用子类化就可以直接使用的,所以你通常可以用很少的代码完成一个集合视图。当你想要做超过系统提供的行为的时候,你可以子类化,并且提供你的自定义行为。

Table 1-1The classes and protocols for implementing collection views 实现集合视图的类和协议

Purpose

目的

Classes/Protocols

类/协议

Description/ 描述

Top-level containment and management

最高级的包含和管理

AUICollectionViewobject defines the visible area for your collection view’s content. This class descends fromand can contain a large scrollable area as needed. This class also facilitates the presentation of your data based on the layout information it receives from its layout object.

UICollectionView为你的集合视图内容定义了可视区域。这个类继承自UIScrollView可以按照需要包含一片挺大的滚动区域。这个类很便于展示你的基于从布局对象获取的布局信息的数据。

AUICollectionViewControllerobject provides view controller–level management support for a collection view. Its use is optional.

UICollectionViewController 对象为集合视图提供了视图控制器级别的管理,他的使用是可选的。

Content management

内容管理

protocol

protocol

Thedata source objectis the most important object associated with the collection view and is one that you must provide. The data source manages the content of the collection view and creates the views needed to present that content. To implement a data source object, you must create an object that conforms to theUICollectionViewDataSourceprotocol.

数据源对象是和集合视图有关的最重要的对象同事你必须完成他。数据源管理着集合视图的内容同时创建内容上的视图。为了实现数据源对象,你需要创建一个遵守数据源协议的对象。

The collection viewdelegateobject lets you intercept interesting messages from the collection view and customize the view’s behavior. For example, you use a delegate object to track the selection and highlighting of items in the collection view. Unlike the data source object, the delegate object is optional.

集合视图协议对象让你可以拦截集合对象的有趣的信息,同时自定义视图行为。比如,你可以使用这个协议对象来跟踪选择,同时突出被选择的元素。和数据源对象不同的是,delegate的完成是可选的。

For information about how to implement the data source and delegate objects, seeDesigning Your Data Source and Delegate.

更多关于数据源和协议的资料,请见《设计你的数据源和协议》

Presentation

展示

All views displayed in a collection view must be instances of theUICollectionReusableViewclass. This class supports a recycling mechanism in use by collection views. Recycling views (instead of creating new ones) improves performance in general and especially improves it during scrolling.

所有集合视图中展示的视图都必须是UICollectionReusableView类的实例,这个类提供了集合视图中使用的回收机制。回收视图(替代创建新视图)一般可以提高新能,尤其是在滚动视图的时候

AUICollectionViewCellobject is a specific type of reusable view that you use for your main data items.

UICollectionViewCell对象是特定的一种重用视图,你用它作为你主要的数据项。

Layout

布局

教育人的诗句或名言警句,激励人在逆境中脱颖而出的话

IOS 集合视图指南2:集合视图基础

相关文章:

你感兴趣的文章:

标签云: