Layouts
Arrange your collection view content in a highly configurable layout.
--以高度可配置的布局 排列集合视图内容。
Overview --概览
A collection view layout defines the visual arrangement of the content in your collection. Layouts are designed to be flexible to let you create any kind of arrangement you need for your content, from simple to complex. The simplest type of collection view layout displays its items in a grid, but you can define layouts to arrange items however you like. For example, you might create a layout where items are arranged in a circle or vary in size. You can also change layouts dynamically at runtime whenever you need to present items differently, such as when a user rotates the device.
--collection view的layout定义了集合中内容的视觉排列。布局的设计是灵活的,允许您为内容创建任何类型的排列,从简单到复杂。最简单的集合视图布局类型是在网格中显示其item,但您可以根据需要自定义布局来排列各items。例如,您可以创建一个布局,其中的item根据圆形排列 或 根据大小变化的。无论何时,当你需要以不同风格展示items时,你还可以在运行时动态更改布局,例如当用户旋转设备时。
Collection view layouts are customizable and highly visual. For example, the App Store app uses a single collection view with custom layouts per section to showcase different kinds of content.
--Collection view layouts是可定制的和高度可视化的。例如,App Store应用程序使用单个集合视图,当这个单个集合视图的每个部分都有自定义的布局,以显示不同类型的内容。
Topics --专题
Essentials --本质
Using Collection View Compositional Layouts and Diffable Data Sources --使用综合布局和不同数据源的示例
Learn how to bring complex, high-performance layouts to your app, and simplify updating and managing your UI.
class UICollectionViewCompositionalLayout
A layout object that lets you combine items in highly adaptive and flexible visual arrangements.
--一个布局对象,允许你组合的item的布局具有高度的适应性和灵活性
Components --组件
class NSCollectionLayoutItem
The most basic component of a collection view's layout.
class NSCollectionLayoutGroup
A container for a set of items that lays out the items along a path.
class NSCollectionLayoutSection
A container that combines a set of groups into distinct visual groupings.
Size and Spacing --尺寸和间距
class NSCollectionLayoutDimension
An individual dimension of an item's size (width or height) in a collection view.
class NSCollectionLayoutSize
The width and the height of an item in a collection view.
class NSCollectionLayoutSpacing
An object that defines the space between or around items in a collection view.
class NSCollectionLayoutEdgeSpacing
An object that defines the space around the edges of items in a collection view.
protocol NSCollectionLayoutContainer
A protocol used to provide information about the size and content insets of a layout's container.
Configuration --配置
class UICollectionViewCompositionalLayoutConfiguration
An object that defines scroll direction, section spacing, and headers or footers for the layout.
typealias UICollectionViewCompositionalLayoutSectionProvider
A closure that creates and returns each of the layout's sections.
protocol NSCollectionLayoutEnvironment
A protocol used to provide information about the layout's container and environment traits, such as size classes and display scale factor.
Interaction --交互
enum UICollectionLayoutSectionOrthogonalScrollingBehavior
The scrolling behavior of the layout's sections in relation to the main layout axis.
Appearance --外观
class NSCollectionLayoutAnchor
An object that defines how to attach a supplementary item to an item in a collection view.
class NSCollectionLayoutSupplementaryItem
An object used to add an extra visual decoration, such as a badge or a frame, to an item in a collection view.
class NSCollectionLayoutBoundarySupplementaryItem
An object used to add headers or footers to a collection view.
class NSCollectionLayoutDecorationItem
An object used to add a background to a section of a collection view.
Advanced Layouts --高阶布局
class NSCollectionLayoutGroupCustomItem
An item used in a group with a custom layout arrangement.
typealias NSCollectionLayoutGroupCustomItemProvider
A closure that creates and returns each of the custom group's items.
Layout Updates --布局更新
protocol NSCollectionLayoutVisibleItem
An item that's currently visible within the bounds of a section.
typealias NSCollectionLayoutSectionVisibleItemsInvalidationHandler
A closure called before each layout cycle to allow modification of items in a section immediately before they are displayed.
class UICollectionViewUpdateItem
An object that describes a single change to make to an item in a collection view.
class UICollectionViewFocusUpdateContext
A context object that stores information specific to a focus update in a collection view.
class UICollectionViewLayoutInvalidationContext
A context object that declares which parts of your layout need to be updated when the layout is invalidated.
Manual Layouts --手动布局
Customizing Collection View Layouts
Customize a view layout by changing the size of cells in the flow or implementing a mosaic style.
class UICollectionViewLayout
An abstract base class for generating layout information for a collection view.
class UICollectionViewFlowLayout
A concrete layout object that organizes items into a grid with optional header and footer views for each section.
class UICollectionViewTransitionLayout
A special type of layout object that lets you implement behaviors when changing from one layout to another in your collection view.
class UICollectionViewLayoutAttributes
A layout object that manages the layout-related attributes for a given item in a collection view.
class UICollectionViewFlowLayoutInvalidationContext
A set of properties for determining whether to recompute the size of items or their position in the layout.
See Also
Layouts
Using Collection View Compositional Layouts and Diffable Data Sources
Learn how to bring complex, high-performance layouts to your app, and simplify updating and managing your UI.