About iOS Collection Views

关于iOS Collection Views

A collection view is a way to present an ordered set of data items using a flexible and changeable layout. The most common use for collection views is to present items in a grid-like arrangement, but collection views in iOS are capable of more than just rows and columns. With collection views, the precise layout of visual elements is definable through subclassing and can be changed dynamically. So you can implement grids, stacks, circular layouts, dynamically changing layouts, or any type of arrangement you can imagine.

collection view 是运用一个灵活多变的布局呈现一系列有序数据项的一种方法。collection view最通常的使用使用像网格状排列来呈现数据项,但是iOS的collection view 的能力不仅限于行和列。使用collection views, 视觉元素的精确布局可通过子类化定义并被动态改变。所以你可以实现网格,栈,圆形布局,动态改变布局,或任何你可以想象的排列布局。

Collection views keep a strict separation between the data being presented and the visual elements used to present that data. Your app is solely responsible for managing the data. Your app also provides the view objects used to present that data. After that, the collection view takes your views and does all the work of positioning them onscreen. It does this work in conjunction with a layout object, whose job is to specify the placement and visual attributes for your views. Thus, you provide the data, the layout object provides the placement information, and the collection view merges the two pieces together to achieve the final appearance.

Collection views 严格分离被呈现的数据和用来呈现这些数据的视觉元素。应用程序只负责管理这些数据,以及提供用来呈现这些数据的视图对象。然后collection view接手这些视图,并完成所有的工作把数据定位在屏幕上。它和一个层对象(layout object)联合工作,该层对象的工作是指定视图的位置和可视化属性。因此,你提供数据,层对象提供位置信息,collection view 把这两部分融合在一起来达到最后的外观。

At a Glance(概览)

The standard iOS collection view classes provide all of the behavior you need to implement simple grids. You can also extend the standard classes to support custom layouts and specific interactions with those layouts.

标准iOS collection view 类提供了实现简单网格的所有行为(behavior)。你也可以扩展标准类来支持自定义布局,来实现跟那些布局的特殊交互。

A Collection View Manages the Visual Presentation of Data Driven Views

Collection View 管理驱动视图的可视化数据呈现

A collection view facilitates the presentation of data-driven views provided by your app. The collection view’s only concern is about taking your views and laying them out in a specific way. The collection view is all about the presentation and arrangement of your views and not about their content. Understanding the interactions between the collection view, the layout object, and your custom objects is crucial for using collection views in your app.

collection view 促进应用程序提供的数据驱动(data-driven)视图的呈现。collection view 的唯一关注点是接手你的视图并以特定的方式把它们布局到屏幕上。collection view 关注的是视图的呈现和排列,而不是关于它们的内容。想要在应用里使用collection view, 理解collection view, 层对象,以及你的自定义对象之间的交互是至关重要的。

The Flow Layout Supports Grids and Other Line-Oriented Presentations

流布局支持网格和其它面向线条的表现方式

A flow layout object is a concrete layout object provided by UIKit. You typically use the flow layout object to implement grids—that is, rows and columns of items—but the flow layout supports any type of linear flow. Because it is not just for grids, you can use the flow layout to create interesting and flexible arrangements of your content both with and without subclassing. The flow layout supports items of different sizes, variable spacing of items, custom headers and footers, and custom margins without subclassing. And subclassing allows you to tweak the behavior of the flow layout class even further.

流布局(flow layout)对象 是UIKit提供的一个具体布局对象。 通常你使用它来实现网格---就是,数据项的行和列---但是流布局还支持任何类型的线性流。因为它不仅限于网格,你可以使用它来为你的内容创建各种有趣复杂的排列,既可以子类化它也可以直接使用。 流布局支持不同尺寸的数据项, 项的间距可变,可以自定义页头(header)和页脚(footer), 已经无需子类化就可以定制页边空白(margin)。 子类化能让你更进一步的调整流布局类的行为。

Relevant chapter: “Using the Flow Layout”

相关章节:“Using the Flow Layout”

Gesture Recognizers Can Be Used for Cell and Layout Manipulations

手势识别能用于单元(cell)和布局操作

Like all views, you can attach gesture recognizers to a collection view to manipulate the content of that view. Because a collection view involves the collaboration of multiple views, it helps to understand some basic techniques for incorporating gesture recognizers into your collection views. You can use gesture recognizers to tweak layout attributes or to manipulate items in the collection view.

就像所有视图一样,你可以在collection view里采用手势识别来操作视图的内容。因为collection view 涉及了多个视图的协作, 在collection view 里结合手势识别能有助于理解一些基本技术。你可以在collection view里调整(tweak)层属性或操作数据项。

Custom Layouts Let You Go Beyond Grids

自定义布局让你超越网格布局

The basic layout object can be subclassed to implement custom layouts for your app. Designing a custom layout does not require a large amount of code in most cases. However, it helps to understand how layouts work so that you can design your layout objects to be efficient.

基本的布局对象能被子类化来实现应用程序里的自定义布局。 在大多数情况下,自定义布局不需要大量的的代码。 然而,它能帮助你理解布局是如何工作的,那样你就能设计高效的布局对象。

Prerequisites(先决条件)

Before reading this document, you should have a solid understanding of the role views play in iOS apps. If you are new to iOS programming and not familiar with the iOS view architecture, read View Programming Guide for iOS before reading this book.

在你阅读本文章之前,你应该对iOS应用中的视图有一个坚实的理解。如果你是iOS编程的新手,不熟悉iOS视图架构,请先阅读View Programming Guide for iOS

See Also(同时查看)

For a guided overview of collection views, see the following WWDC videos:

collection views的指导性概述,请看以下WWDC视频:

Collection views are somewhat related to table views, in that both present ordered data to the user. However, the visual presentation of table views is geared around a single-column layout, whereas collection views can support many different layouts. For more information about table views, see Table View Programming Guide for iOS.

Collection views 跟表格视图(table views)有一些关联, 两者都是给用户呈现有序数据。然而,表格视图的视觉呈现是面向单列布局,而collection views 能支持很多不同的布局。 关于表格视图的更多信息,请看Table View Programming Guide for iOS.

Collection View Programming Guide for iOS---(一)----About iOS Collection Views的更多相关文章

  1. Collection View Programming Guide for iOS---(七)---Custom Layouts: A Worked Example

    Custom Layouts: A Worked Example Creating a custom collection view layout is simple with straightfor ...

  2. Collection View Programming Guide for iOS---(五)---Incorporating Gesture Support

      Incorporating Gesture Support 结合手势支持 You can add greater interactivity to your collection views th ...

  3. Collection View Programming Guide for iOS---(六)---Creating Custom Layouts

    Creating Custom Layouts 创建自定义布局 Before you start building custom layouts, consider whether doing so ...

  4. Collection View Programming Guide for iOS---(二)----Collection View Basics

      Collection View Basics Collection View 基础 To present its content onscreen, a collection view coope ...

  5. Collection View Programming Guide for iOS---(三)---Designing Your Data Source and Delegate

      Designing Your Data Source and Delegate 设计你的数据源和委托 Every collection view must have a data source o ...

  6. Collection View Programming Guide for iOS---(四)---Using the Flow Layout

      Using the Flow Layout使用流布局 The UICollectionViewFlowLayout class is a concrete layout object that y ...

  7. View Programming Guide for iOS ---- iOS 视图编程指南(四)---Views

    Views Because view objects are the main way your application interacts with the user, they have many ...

  8. 【IOS笔记】View Programming Guide for iOS -1

    原文:View Programming Guide for iOS View and Window Architecture Views and windows present your applic ...

  9. View Programming Guide for iOS_读书笔记[正在更新……]

    原文:View Programming Guide for iOS 1 Introduction 先熟悉一下基本概念. Window Windows do not have any visible c ...

随机推荐

  1. C# 把控件内容导出图片

    Bitmap newbitmap = new Bitmap(panelW.Width, panelW.Height);            panelW.DrawToBitmap(newbitmap ...

  2. 有方向的运动js

    <!doctype html> <html lang="en"> <head>     <meta charset="UTF-8 ...

  3. iOS之中国银联移动支付控件升级的问题

    自从11月以来,如果用户安装了集成了中国银联手机支付SDK的app,那么在使用银联支付的时候,会发现,不能调用银联支付方式,并且弹出一个提示”银联手机支付已升级请更新客户端8100010”.如下图: ...

  4. react 创建组件 (四)Stateless Functional Component

    上面我们提到的创建组件的方式,都是用来创建包含状态和用户交互的复杂组件,当组件本身只是用来展示,所有数据都是通过props传入的时候,我们便可以使用Stateless Functional Compo ...

  5. 批量修改文件权限 和所有者 chown nobody:nobody * -R chmod 775 * -R

    chown nobody:nobody * -R chmod 775 * -R

  6. c++面试题目(3)

    这些东西有点烦,有点无聊.如果要去C++面试就看看吧.几年前网上搜索的.刚才看到,就整理一下,里面有些被我改了,感觉之前说的不对或不完善. 1.求下面函数的返回值( 微软) int func(x)  ...

  7. Variable 'bop' is uninitialized when captured by block

    代码: - (void)doTest { NSBlockOperation * bop = [NSBlockOperation blockOperationWithBlock:^{ if (!bop. ...

  8. 浅谈MySQL压缩协议细节--从源码层面

    压缩协议属于mysql通讯协议的一部分,要启用压缩协议传输功能,前提条件客户端和服务端都必须要支持zlib算法,那么,现在有个问题,假如服务端已经默认开启压缩功能,那原生客户端在连接的时候要如何才可启 ...

  9. 【转载】轻松搞懂WebService工作原理

    用更简单的方式给大家谈谈WebService,让你更快更容易理解,希望对初学者有所帮助. WebService是基于网络的.分布式的模块化组件. 我们直接来看WebService的一个简易工作流程: ...

  10. MergeLinklist

    写了一个合并有序链表,代码有点纠结啊.涉及到指针就是麻烦,DS课曹老师课件说linklist是DS的难点. . . 假设数组就非常easy了.链表就要小心. 里面遇到的一些情况.第一.最好是先确定l1 ...