{"id":348656,"date":"2023-06-12T15:00:21","date_gmt":"2023-06-12T15:00:21","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=348656"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=348656","title":{"rendered":"<span>UICollectionViewCompositionalLayout<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d62\/062\/425\/d62062425ce6ed62a35d2eeff694bc4e.png\" width=\"676\" height=\"1024\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d62\/062\/425\/d62062425ce6ed62a35d2eeff694bc4e.png\"\/><\/figure>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043f\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u043a UICollectionViewCompositionalLayout \u0438 \u0441 \u0435\u0433\u043e \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043e\u0437\u0434\u0430\u0442\u044c UICollectionView \u0441 \u043f\u0440\u043e\u043a\u0440\u0443\u0447\u0438\u0432\u0430\u044e\u0449\u0438\u043c\u0438\u0441\u044f \u0441\u0435\u043a\u0446\u0438\u044f\u043c\u0438, \u0430 \u0437\u0430\u0442\u0435\u043c \u0435\u0449\u0435 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0431\u043e\u043b\u0435\u0435 \u0438\u0445 \u043a\u0430\u0441\u0442\u043e\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043a\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e UICollectionViewCompositionalLayout \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c UICollectionView, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a \u043a\u0430\u043a \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e.<\/p>\n<p>\u0421\u0442\u0430\u0442\u044c\u044f \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0430 \u043d\u0430 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 apple\u00a0Implementing Modern Collection Views<\/p>\n<p><a href=\"https:\/\/developer.apple.com\/documentation\/uikit\/views_and_controls\/collection_views\/implementing_modern_collection_views\" rel=\"noopener noreferrer nofollow\"><u>https:\/\/developer.apple.com\/documentation\/uikit\/views_and_controls\/collection_views\/implementing_modern_collection_views<\/u><\/a><\/p>\n<p>Compositional layouts &#8212; \u044d\u0442\u043e \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u0432\u0438\u0434 API, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u043c\u0430\u043a\u0435\u0442\u044b \u043f\u0443\u0442\u0435\u043c \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0433\u0440\u0443\u043f\u043f \u043c\u0430\u043a\u0435\u0442\u043e\u0432. Compositional layouts \u0438\u043c\u0435\u044e\u0442 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u044e, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0443\u044e \u0438\u0437 Item, Group, Sections, and Layout.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043b\u044e\u0431\u043e\u0439\u00a0Compositional layouts, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0447\u0435\u0442\u044b\u0440\u0435 \u043a\u043b\u0430\u0441\u0441\u0430:<\/p>\n<p><strong>NSCollectionLayoutSize:<\/strong>\u00a0\u0420\u0430\u0437\u043c\u0435\u0440\u044b \u0448\u0438\u0440\u0438\u043d\u044b \u0438 \u0432\u044b\u0441\u043e\u0442\u044b \u043e\u0442\u043d\u043e\u0441\u044f\u0442\u0441\u044f \u043a \u0442\u0438\u043f\u0443\u00a0<strong>NSCollectionLayoutDimension<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b \u043f\u0443\u0442\u0435\u043c \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0434\u043e\u043b\u0438 \u0448\u0438\u0440\u0438\u043d\u044b\/\u0432\u044b\u0441\u043e\u0442\u044b \u043c\u0430\u043a\u0435\u0442\u0430 (\u0432 \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u0430\u0445 \u043f\u043e \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044e \u043a \u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0443) \u0438\u043b\u0438 \u043f\u0443\u0442\u0435\u043c \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u044b\u0445 \u0438\u043b\u0438 \u0440\u0430\u0441\u0447\u0435\u0442\u043d\u044b\u0445 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u0432.<\/p>\n<p><strong>NSCollectionLayoutItem:<\/strong>\u00a0\u042d\u0442\u043e \u044f\u0447\u0435\u0439\u043a\u0430 \u043d\u0430\u0448\u0435\u0433\u043e \u043c\u0430\u043a\u0435\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u044d\u043a\u0440\u0430\u043d\u0435 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0440\u0430\u0437\u043c\u0435\u0440\u0430.<\/p>\n<p><strong>NSCollectionLayoutGroup:<\/strong>\u00a0\u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u00a0<strong>NSCollectionLayoutItem<\/strong>\u00a0\u0432 \u0433\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u044c\u043d\u043e\u0439, \u0432\u0435\u0440\u0442\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0439 \u0438\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0439 \u0444\u043e\u0440\u043c\u0430\u0445.<\/p>\n<p><strong>NSCollectionLayoutSection<\/strong>: \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0435\u043a\u0446\u0438\u0438 \u043f\u0443\u0442\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 <strong>NSCollectionLayoutGroup<\/strong>. \u0421\u0435\u043a\u0446\u0438\u0438 \u0432 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0438\u0442\u043e\u0433\u0435 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 <strong>\u0421ompositionalLayout.<\/strong><\/p>\n<p>Sections \u0438 items\u00a0\u0432\u00a0<strong>\u0421ompositionalLayout\u00a0<\/strong>\u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442\u00a0Sections \u0438 items \u043a\u043b\u0430\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0421ollectionViewDataSource. \u0413\u0440\u0443\u043f\u043f\u044b, \u043e\u0434\u043d\u0430\u043a\u043e, \u043d\u0435 \u0438\u043c\u0435\u044e\u0442 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u0430 \u0432 \u0421ollectionViewDataSource\u00a0\u0438 \u043d\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u044e\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0432 \u0432\u0438\u0434\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \/ \u044f\u0447\u0435\u0435\u043a. \u041e\u043d\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430\u0448\u0438\u0445 Items \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 Section.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/873\/e08\/2f0\/873e082f0f8f73560273b02923f8b377.png\" width=\"939\" height=\"939\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/873\/e08\/2f0\/873e082f0f8f73560273b02923f8b377.png\"\/><\/figure>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u0438 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c CollectionView c\u043e \u0441\u043a\u0440\u043e\u043b\u044f\u0449\u0438\u043c\u0438\u0441\u044f \u0440\u044f\u0434\u0430\u043c\u0438. \u041c\u044b \u0443\u0432\u0438\u0434\u0438\u043c \u043d\u0430\u0441\u043a\u043e\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e\u00a0\u0421ompositionalLayout\u00a0\u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 \u0442\u0440\u0430\u0434\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u043c, \u043a\u043e\u0433\u0434\u0430 \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u044f \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0433\u043e \u044d\u0444\u0444\u0435\u043a\u0442\u0430 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u0432\u043d\u0435\u0434\u0440\u044f\u0442\u044c\u00a0CollectionView \u0432 \u0434\u0440\u0443\u0433\u0438\u0435 CollectionView.<\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043b\u0430\u0441\u0441\u00a0ViewController, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0443 UICollectionViewDelegate:<\/p>\n<pre><code class=\"swift\">class ViewController: UIViewController, UICollectionViewDelegate {  }<\/code><\/pre>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0432 \u043d\u0435\u0433\u043e \u0434\u0432\u0430 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 dataSource \u0438 collectionView:<\/p>\n<pre><code class=\"swift\">var dataSource: UICollectionViewDiffableDataSource&lt;Int, Int>! = nil      var collectionView: UICollectionView! = nil<\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043b\u0430\u0441\u0441 \u044f\u0447\u0435\u0439\u043a\u0438 \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0439 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438:<\/p>\n<pre><code class=\"swift\">class TextCell: UICollectionViewCell {     let label = UILabel()     static let reuseIdentifier = \"text-cell-reuse-identifier\"      override init(frame: CGRect) {         super.init(frame: frame)         configure()     }     required init?(coder: NSCoder) {         fatalError(\"not implemnted\")     } }<\/code><\/pre>\n<p>\u0412 \u044d\u043a\u0441\u0442\u0435\u043d\u0448\u0435\u043d\u0435 \u0437\u0430\u0434\u0430\u0434\u0438\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0435\u0439\u043d\u0442\u044b:<\/p>\n<pre><code class=\"swift\">extension TextCell {     func configure() {         label.translatesAutoresizingMaskIntoConstraints = false         label.adjustsFontForContentSizeCategory = true         contentView.addSubview(label)         label.font = UIFont.preferredFont(forTextStyle: .caption1)         let inset = CGFloat(10)         NSLayoutConstraint.activate([             label.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: inset),             label.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -inset),             label.topAnchor.constraint(equalTo: contentView.topAnchor, constant: inset),             label.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -inset)             ])     } }<\/code><\/pre>\n<p>\u041c\u044b \u043f\u043e\u0434\u043e\u0448\u043b\u0438 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043a \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u043b\u044d\u0439\u0430\u0443\u0442\u0430. \u0412\u044b\u043d\u0435\u0441\u0435\u043c \u0435\u0433\u043e \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434:<\/p>\n<pre><code class=\"swift\">func createLayout() -> UICollectionViewLayout {         let layout = UICollectionViewCompositionalLayout {             (sectionIndex: Int, layoutEnvironment: NSCollectionLayoutEnvironment) -> NSCollectionLayoutSection? in  \/\/ \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u0435\u043c Item. \u0417\u0430\u0434\u0430\u0435\u043c \u0435\u043c\u0443 \u0448\u0438\u0440\u0438\u043d\u0443 \u0438 \u0432\u044b\u0441\u043e\u0442\u0443 \u0433\u0440\u0443\u043f\u043f\u044b,  \/\/ \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043c\u0435\u0449\u0435\u043d. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0437\u0430\u0434\u0430\u0435\u043c widthDimension \u0438  \/\/ heightDimension \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f .fractionalWidth(1.0) \u0438 .fractionalHeight(1.0) \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e. \/\/ \u0422\u0430\u043a \u0436\u0435 \u0437\u0430\u0434\u0430\u0435\u043c \u0443 Item \u043e\u0442\u0441\u0442\u0443\u043f\u044b \u0447\u0435\u0440\u0435\u0437 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e contentInsets.                      let item = NSCollectionLayoutItem(             layoutSize: NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0),                                                   heightDimension: .fractionalHeight(1.0)))             item.contentInsets = NSDirectionalEdgeInsets(top: 10, leading: 10, bottom: 10, trailing: 10)   \/\/ \u0421\u043e\u0437\u0434\u0430\u0435\u043c Group \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0433\u0430\u044e\u0442\u0441\u044f \u0433\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u044c\u043d\u043e.  \/\/ \u0417\u0430\u0434\u0430\u0435\u043c \u0435\u0439 \u0448\u0438\u0440\u0438\u043d\u0443 85% \u0448\u0438\u0440\u0438\u043d\u044b \u044d\u043a\u0440\u0430\u043d\u0430 \u0438 \u0432\u044b\u0441\u043e\u0442\u0443 40% \u0432\u044b\u0441\u043e\u0442\u044b \u044d\u043a\u0440\u0430\u043d\u0430. \/\/ \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 Group \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u0432\u044b\u0448\u0435 Item                      let containerGroup = NSCollectionLayoutGroup.horizontal(             layoutSize: NSCollectionLayoutSize(widthDimension: .fractionalWidth(0.85),                                                   heightDimension: .fractionalHeight(0.4)),             subitems: [item])              \/\/ \u0421\u043e\u0437\u0434\u0430\u0435\u043c Section, \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u044f \u0432 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0443\u044e \u0432\u044b\u0448\u0435 Group.  \/\/ \u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0441\u0435\u043a\u0446\u0438\u044f \u0438\u043c\u0435\u043b\u0430 \u0432\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u043a\u0440\u043e\u043b\u0438\u0442\u044c\u0441\u044f \u0437\u0430\u0434\u0430\u0435\u043c \u0435\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e   \/\/ orthogonalScrollingBehavior.                 let section = NSCollectionLayoutSection(group: containerGroup)         section.orthogonalScrollingBehavior = .continuous          return section      }      return layout }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0421ollectionView, \u043f\u0435\u0440\u0435\u0434\u0430\u0432 \u0432 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 \u043b\u044d\u0439\u0430\u0443\u0442, \u043a\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043d\u0430\u043c\u0438 \u043c\u0435\u0442\u043e\u0434.<\/p>\n<p>\u0412\u044b\u043d\u0435\u043c\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0438 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e \u0421ollectionView \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434.<\/p>\n<pre><code class=\"swift\"> func configureHierarchy() {         collectionView = UICollectionView(frame: view.bounds, collectionViewLayout: createLayout())         collectionView.autoresizingMask = [.flexibleWidth, .flexibleHeight]         collectionView.backgroundColor = .systemMint         view.addSubview(collectionView)         collectionView.delegate = self  }<\/code><\/pre>\n<p>\u0418 \u0432\u044b\u0437\u043e\u0432\u0435\u043c \u0435\u0433\u043e \u0432\u043e viewDidLoad.<\/p>\n<pre><code class=\"swift\"> override func viewDidLoad() {         super.viewDidLoad()          navigationItem.title = \"Scrollable rows\"         configureHierarchy()   }<\/code><\/pre>\n<p>\u041d\u0430\u043c \u043e\u0441\u0442\u0430\u043b\u0441\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0448\u0430\u0433. \u0421\u043e\u0437\u0434\u0430\u0442\u044c \u0438 \u0441\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c DataSource.<\/p>\n<pre><code class=\"swift\">func configureDataSource() {  \/\/ \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043c\u0430\u0441\u0441\u0438\u0432 \u044d\u043c\u043e\u0434\u0436\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u0432 \u044f\u0447\u0435\u0439\u043a\u0430\u0445 \u043d\u0430\u0448\u0435\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b          let emojies = [\"?\", \"?\", \"?\", \"?\", \"?\", \"?\",\"?\", \"?\", \"?\"]     \/\/ \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c  CellRegistration \u0441 \u0442\u0438\u043f\u043e\u043c \u043d\u0430\u0448\u0435\u0439 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u0439 \u044f\u0447\u0435\u0439\u043a\u0438. \u0418 \u0441\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u0443\u0435\u043c \u043d\u0430\u0448\u0443 \u044f\u0447\u0435\u0439\u043a\u0443.             let cellRegistration = UICollectionView.CellRegistration&lt;TextCell, Int> { (cell, indexPath, identifier) in                          cell.label.text = \"\\(emojies[indexPath.item])\"             cell.contentView.backgroundColor = .systemCyan             cell.contentView.layer.borderColor = UIColor.black.cgColor             cell.contentView.layer.borderWidth = 1             cell.contentView.layer.cornerRadius = 8             cell.label.textAlignment = .center             cell.label.font = UIFont.systemFont(ofSize: 150)         }         \/\/ \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c  UICollectionViewDiffableDataSource \u043f\u0435\u0440\u0435\u0434\u0430\u0432 \u0432 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 collectionView.           dataSource = UICollectionViewDiffableDataSource&lt;Int, Int>(collectionView: collectionView) {             (collectionView: UICollectionView, indexPath: IndexPath, identifier: Int) -> UICollectionViewCell? in                          return collectionView.dequeueConfiguredReusableCell(using: cellRegistration, for: indexPath, item: identifier)         }     \/\/ \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c  NSDiffableDataSourceSnapshot \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0443\u043a\u0430\u0436\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0435\u043a\u0446\u0438\u0439  \/\/ \u0438 \u0430\u0439\u0442\u0435\u043c\u043e\u0432 \u0432 \u0441\u0435\u043a\u0446\u0438\u0438. \/\/ NSDiffableDataSourceSnapshot \u2014 \u044d\u0442\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u043e view  \/\/ \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u0438.  \/\/ DiffableDataSource \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 Snapshot \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445  \/\/ \u0434\u043b\u044f \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439 \u0438 \u0442\u0430\u0431\u043b\u0438\u0446. \u041c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c Snapshot \u0434\u043b\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438  \/\/ \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445, \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c\u044b\u0445 \u0432 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438,  \/\/ \u043c\u044b \u0442\u0430\u043a \u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 Snapshot \u0434\u043b\u044f \u043e\u0442\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0432 \u0434\u0430\u043d\u043d\u044b\u0445,  \/\/ \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c\u044b\u0445 \u0432 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438. \/\/ \u0414\u0430\u043d\u043d\u044b\u0435 \u0432 Snapshot \u0441\u043e\u0441\u0442\u043e\u044f\u0442 \u0438\u0437 sections  \u0438 items, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c, \/\/ \u0432 \u0442\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0441\u0430\u043c\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c.  \/\/ \u041c\u044b \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c \u0432\u0438\u0434 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044f, \u0443\u0434\u0430\u043b\u044f\u044f \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u044f  \/\/ sections \u0438 items.            var snapshot = NSDiffableDataSourceSnapshot&lt;Int, Int>()         var identifierOffset = 0         let itemsPerSection = 9         for section in 0..&lt;5 {             snapshot.appendSections([section])             let maxIdentifier = identifierOffset + itemsPerSection             snapshot.appendItems(Array(identifierOffset..&lt;maxIdentifier))             identifierOffset += itemsPerSection         }         dataSource.apply(snapshot, animatingDifferences: false)     }<\/code><\/pre>\n<p>\u0412\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043d\u0430\u0448 \u043c\u0435\u0442\u043e\u0434 \u0432\u043e viewDidLoad.<\/p>\n<pre><code class=\"swift\"> override func viewDidLoad() {         super.viewDidLoad()         navigationItem.title = \"Scrollable rows\"         configureHierarchy()         configureDataSource()     }<\/code><\/pre>\n<p>\u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"swift\">import UIKit  class ViewController: UIViewController, UICollectionViewDelegate {          var dataSource: UICollectionViewDiffableDataSource&lt;Int, Int>! = nil     var collectionView: UICollectionView! = nil      override func viewDidLoad() {         super.viewDidLoad()         navigationItem.title = \"Scrollable rows\"         configureHierarchy()         configureDataSource()     }          func configureHierarchy() {         collectionView = UICollectionView(frame: view.bounds, collectionViewLayout: createLayout())         collectionView.autoresizingMask = [.flexibleWidth, .flexibleHeight]         collectionView.backgroundColor = .systemMint         view.addSubview(collectionView)         collectionView.delegate = self     }          func configureDataSource() {         let emojies = [\"?\", \"?\", \"?\", \"?\", \"?\", \"?\",\"?\", \"?\", \"?\"]                  let cellRegistration = UICollectionView.CellRegistration&lt;TextCell, Int> { (cell, indexPath, identifier) in                          cell.label.text = \"\\(emojies[indexPath.item])\"             cell.contentView.backgroundColor = .systemCyan             cell.contentView.layer.borderColor = UIColor.black.cgColor             cell.contentView.layer.borderWidth = 1             cell.contentView.layer.cornerRadius = 8             cell.label.textAlignment = .center             cell.label.font = UIFont.systemFont(ofSize: 150)         }                  dataSource = UICollectionViewDiffableDataSource&lt;Int, Int>(collectionView: collectionView) {             (collectionView: UICollectionView, indexPath: IndexPath, identifier: Int) -> UICollectionViewCell? in                          return collectionView.dequeueConfiguredReusableCell(using: cellRegistration, for: indexPath, item: identifier)         }                  var snapshot = NSDiffableDataSourceSnapshot&lt;Int, Int>()         var identifierOffset = 0         let itemsPerSection = 9         for section in 0..&lt;5 {             snapshot.appendSections([section])             let maxIdentifier = identifierOffset + itemsPerSection             snapshot.appendItems(Array(identifierOffset..&lt;maxIdentifier))             identifierOffset += itemsPerSection         }         dataSource.apply(snapshot, animatingDifferences: false)     }          func createLayout() -> UICollectionViewLayout {         let layout = UICollectionViewCompositionalLayout {             (sectionIndex: Int, layoutEnvironment: NSCollectionLayoutEnvironment) -> NSCollectionLayoutSection? in                           let item = NSCollectionLayoutItem(                 layoutSize: NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0),                                                   heightDimension: .fractionalHeight(1.0)))             item.contentInsets = NSDirectionalEdgeInsets(top: 10, leading: 10, bottom: 10, trailing: 10)                           let containerGroup = NSCollectionLayoutGroup.horizontal(                 layoutSize: NSCollectionLayoutSize(widthDimension: .fractionalWidth(0.85),                                                   heightDimension: .fractionalHeight(0.4)),                 subitems: [item])                                       let section = NSCollectionLayoutSection(group: containerGroup)             section.orthogonalScrollingBehavior = .continuous              return section          }         return layout     } }  class TextCell: UICollectionViewCell {     let label = UILabel()     static let reuseIdentifier = \"text-cell-reuse-identifier\"      override init(frame: CGRect) {         super.init(frame: frame)         configure()     }     required init?(coder: NSCoder) {         fatalError(\"not implemnted\")     } }  extension TextCell {     func configure() {         label.translatesAutoresizingMaskIntoConstraints = false         label.adjustsFontForContentSizeCategory = true         contentView.addSubview(label)         label.font = UIFont.preferredFont(forTextStyle: .caption1)         let inset = CGFloat(10)         NSLayoutConstraint.activate([             label.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: inset),             label.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -inset),             label.topAnchor.constraint(equalTo: contentView.topAnchor, constant: inset),             label.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -inset)             ])     } }<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c CollectionView \u0441 \u0440\u044f\u0434\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u0440\u043e\u043b\u0438\u0442\u044c.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/050\/509\/5f3\/0505095f306f1070be4d4c6880b76e3f.png\" width=\"800\" height=\"1684\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/050\/509\/5f3\/0505095f306f1070be4d4c6880b76e3f.png\"\/><\/figure>\n<p>\u041d\u043e \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043c\u044b \u0440\u0435\u0448\u0438\u043b\u0438 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0434\u0438\u0437\u0430\u0439\u043d \u0438 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0442\u044c \u044f\u0447\u0435\u0439\u043a\u0438 \u043f\u043e \u0442\u0440\u0438, \u0434\u0432\u0435 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u044b \u0441\u043f\u0440\u0430\u0432\u0430 \u043e\u0442 \u043f\u0435\u0440\u0432\u043e\u0439 \u0438 \u043c\u0435\u043d\u044c\u0448\u0435 \u043f\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0443.<\/p>\n<p>\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e\u00a0UICollectionView Compositional Layout \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u0441 \u043d\u0430\u043f\u0438\u0441\u0430\u0432 \u043b\u0438\u0448\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u043e\u043a \u043a\u043e\u0434\u0430.\u00a0<\/p>\n<p>\u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0440 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u044f\u0447\u0435\u0435\u043a, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u043c \u0440\u0430\u0437\u043c\u0435\u0440 \u0448\u0440\u0438\u0444\u0442\u0430 \u0432 \u044f\u0447\u0435\u0439\u043a\u0438\u00a0\u043d\u0430 50 \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0448\u0438 \u044d\u043c\u043e\u0434\u0436\u0438 \u0430\u043a\u043a\u0443\u0440\u0430\u0442\u043d\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u043b\u0438\u0441\u044c \u0432 \u044f\u0447\u0435\u0439\u043a\u0430\u0445.<\/p>\n<pre><code class=\"swift\">cell.label.font = UIFont.systemFont(ofSize: 50)<\/code><\/pre>\n<p>\u0412\u043e-\u0432\u0442\u043e\u0440\u044b\u0445,\u00a0\u0432 \u043c\u0435\u0442\u043e\u0434\u0435\u00a0createLayout\u00a0\u0443\u0434\u0430\u043b\u0438\u043c\u00a0\u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435\u00a0item:<\/p>\n<pre><code class=\"swift\">let item = NSCollectionLayoutItem(                 layoutSize: NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0),                                                   heightDimension: .fractionalHeight(1.0)))             item.contentInsets = NSDirectionalEdgeInsets(top: 10, leading: 10, bottom: 10, trailing: 10)<\/code><\/pre>\n<p>\u0412-\u0442\u0440\u0435\u0442\u044c\u0438\u0445, \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c leadingItem. \u0417\u0430\u0434\u0430\u0434\u0438\u043c \u0435\u043c\u0443 \u0448\u0438\u0440\u0438\u043d\u0443 \u0440\u0430\u0432\u043d\u0443\u044e 70% \u0448\u0438\u0440\u0438\u043d\u044b \u0433\u0440\u0443\u043f\u043f\u044b.<\/p>\n<pre><code class=\"swift\">let leadingItem = NSCollectionLayoutItem(                 layoutSize: NSCollectionLayoutSize(widthDimension: .fractionalWidth(0.7),                                                   heightDimension: .fractionalHeight(1.0)))             leadingItem.contentInsets = NSDirectionalEdgeInsets(top: 10, leading: 10, bottom: 10, trailing: 10)<\/code><\/pre>\n<p>\u0412-\u0447\u0435\u0442\u0432\u0435\u0440\u0442\u044b\u0445, \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c trailingItem. \u0417\u0430\u0434\u0430\u0434\u0438\u043c \u0435\u043c\u0443 \u0448\u0438\u0440\u0438\u043d\u0443\u00a0\u0440\u0430\u0432\u043d\u0443\u044e\u00a0100% \u0448\u0438\u0440\u0438\u043d\u044b \u0433\u0440\u0443\u043f\u043f\u044b \u0438 \u0432\u044b\u0441\u043e\u0442\u0443 \u0440\u0430\u0432\u043d\u0443\u044e\u00a030%.<\/p>\n<pre><code class=\"swift\"> let trailingItem = NSCollectionLayoutItem(                 layoutSize: NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0),                                                   heightDimension: .fractionalHeight(0.3)))             trailingItem.contentInsets = NSDirectionalEdgeInsets(top: 10, leading: 10, bottom: 10, trailing: 10)<\/code><\/pre>\n<p>\u0412-\u043f\u044f\u0442\u044b\u0445, \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c trailingGroup.\u00a0\u0417\u0430\u0434\u0430\u0434\u0438\u043c \u0435\u0439 \u0448\u0438\u0440\u0438\u043d\u0443\u00a0\u0440\u0430\u0432\u043d\u0443\u044e\u00a030% \u0448\u0438\u0440\u0438\u043d\u044b \u0433\u0440\u0443\u043f\u043f\u044b\u00a0(70% \u0443 \u043d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442\u00a0leadingItem, \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043c\u044b \u0443\u0436\u0435 \u0437\u0430\u0434\u0430\u043b\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u0448\u0438\u0440\u0438\u043d\u0443). \u0412 \u043f\u043e\u043b\u0435\u00a0\u00a0subitem \u043e\u0442\u043c\u0435\u0447\u0430\u0435\u043c, \u0447\u0442\u043e \u0433\u0440\u0443\u043f\u043f\u0430 \u0443 \u043d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u0442\u044c \u0438\u0437 \u0434\u0432\u0443\u0445\u00a0trailingItem.<\/p>\n<pre><code class=\"swift\">let trailingGroup = NSCollectionLayoutGroup.vertical(                 layoutSize: NSCollectionLayoutSize(widthDimension: .fractionalWidth(0.3),                                                   heightDimension: .fractionalHeight(1.0)),                 subitem: trailingItem, count: 2)<\/code><\/pre>\n<p>\u0412-\u0448\u0435\u0441\u0442\u044b\u0445, \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c containerGroup. \u0417\u0430\u0434\u0430\u0434\u0438\u043c \u0435\u0439 \u0448\u0438\u0440\u0438\u043d\u0443 85% \u044d\u043a\u0440\u0430\u043d\u0430 \u0438 \u0432\u044b\u0441\u043e\u0442\u0443 40%. \u041f\u043e\u043c\u0435\u0441\u0442\u0438\u043c \u0432 \u043d\u0435\u0435 leadingItem \u0438 trailingGroup.<\/p>\n<pre><code class=\"swift\">let containerGroup = NSCollectionLayoutGroup.horizontal(                 layoutSize: NSCollectionLayoutSize(widthDimension: .fractionalWidth(0.85),                                                   heightDimension: .fractionalHeight(0.4)),                 subitems: [leadingItem, trailingGroup])<\/code><\/pre>\n<p>\u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u043c\u0435\u0442\u043e\u0434\u0430 createLayout \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"swift\">func createLayout() -> UICollectionViewLayout {         let layout = UICollectionViewCompositionalLayout {             (sectionIndex: Int, layoutEnvironment: NSCollectionLayoutEnvironment) -> NSCollectionLayoutSection? in              let leadingItem = NSCollectionLayoutItem(                 layoutSize: NSCollectionLayoutSize(widthDimension: .fractionalWidth(0.7),                                                   heightDimension: .fractionalHeight(1.0)))             leadingItem.contentInsets = NSDirectionalEdgeInsets(top: 10, leading: 10, bottom: 10, trailing: 10)                           let trailingItem = NSCollectionLayoutItem(                 layoutSize: NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0),                                                   heightDimension: .fractionalHeight(0.3)))             trailingItem.contentInsets = NSDirectionalEdgeInsets(top: 10, leading: 10, bottom: 10, trailing: 10)              let trailingGroup = NSCollectionLayoutGroup.vertical(                 layoutSize: NSCollectionLayoutSize(widthDimension: .fractionalWidth(0.3),                                                   heightDimension: .fractionalHeight(1.0)),                 subitem: trailingItem, count: 2)              let containerGroup = NSCollectionLayoutGroup.horizontal(                 layoutSize: NSCollectionLayoutSize(widthDimension: .fractionalWidth(0.85),                                                   heightDimension: .fractionalHeight(0.4)),                 subitems: [leadingItem, trailingGroup])                                       let section = NSCollectionLayoutSection(group: containerGroup)             section.orthogonalScrollingBehavior = .continuous              return section          }         return layout     }<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0438 \u0442\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u0438 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0439 \u0432\u0438\u0434 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u044b \u0434\u043e\u0431\u0438\u043b\u0438\u0441\u044c \u0437\u0430 \u0448\u0435\u0441\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0448\u0430\u0433\u043e\u0432.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/9ab\/796\/cdc\/9ab796cdca30ddc8a9186c57db3ad546.png\" width=\"800\" height=\"1684\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9ab\/796\/cdc\/9ab796cdca30ddc8a9186c57db3ad546.png\"\/><\/figure>\n<p>\u0411\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043f\u0440\u043e CompositionalLayout \u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0432\u0438\u0434\u044b \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441 \u0435\u0433\u043e \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 Apple, \u0430 \u0442\u0430\u043a \u0436\u0435 \u0438\u0437\u0443\u0447\u0438\u0432 \u0434\u0435\u043c\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 Apple, \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0442\u0430\u043a \u0436\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438.<\/p>\n<p><a href=\"https:\/\/developer.apple.com\/documentation\/uikit\/views_and_controls\/collection_views\/implementing_modern_collection_views\" rel=\"noopener noreferrer nofollow\"><u>https:\/\/developer.apple.com\/documentation\/uikit\/views_and_controls\/collection_views\/implementing_modern_collection_views<\/u><\/a><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/741266\/\"> https:\/\/habr.com\/ru\/articles\/741266\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><\/figure>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043f\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u043a UICollectionViewCompositionalLayout \u0438 \u0441 \u0435\u0433\u043e \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043e\u0437\u0434\u0430\u0442\u044c UICollectionView \u0441 \u043f\u0440\u043e\u043a\u0440\u0443\u0447\u0438\u0432\u0430\u044e\u0449\u0438\u043c\u0438\u0441\u044f \u0441\u0435\u043a\u0446\u0438\u044f\u043c\u0438, \u0430 \u0437\u0430\u0442\u0435\u043c \u0435\u0449\u0435 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0431\u043e\u043b\u0435\u0435 \u0438\u0445 \u043a\u0430\u0441\u0442\u043e\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043a\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e UICollectionViewCompositionalLayout \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c UICollectionView, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a \u043a\u0430\u043a \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e.<\/p>\n<p>\u0421\u0442\u0430\u0442\u044c\u044f \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0430 \u043d\u0430 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 apple\u00a0Implementing Modern Collection Views<\/p>\n<p><a href=\"https:\/\/developer.apple.com\/documentation\/uikit\/views_and_controls\/collection_views\/implementing_modern_collection_views\" rel=\"noopener noreferrer nofollow\"><u>https:\/\/developer.apple.com\/documentation\/uikit\/views_and_controls\/collection_views\/implementing_modern_collection_views<\/u><\/a><\/p>\n<p>Compositional layouts &#8212; \u044d\u0442\u043e \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u0432\u0438\u0434 API, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u043c\u0430\u043a\u0435\u0442\u044b \u043f\u0443\u0442\u0435\u043c \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0433\u0440\u0443\u043f\u043f \u043c\u0430\u043a\u0435\u0442\u043e\u0432. Compositional layouts \u0438\u043c\u0435\u044e\u0442 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u044e, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0443\u044e \u0438\u0437 Item, Group, Sections, and Layout.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043b\u044e\u0431\u043e\u0439\u00a0Compositional layouts, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0447\u0435\u0442\u044b\u0440\u0435 \u043a\u043b\u0430\u0441\u0441\u0430:<\/p>\n<p><strong>NSCollectionLayoutSize:<\/strong>\u00a0\u0420\u0430\u0437\u043c\u0435\u0440\u044b \u0448\u0438\u0440\u0438\u043d\u044b \u0438 \u0432\u044b\u0441\u043e\u0442\u044b \u043e\u0442\u043d\u043e\u0441\u044f\u0442\u0441\u044f \u043a \u0442\u0438\u043f\u0443\u00a0<strong>NSCollectionLayoutDimension<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b \u043f\u0443\u0442\u0435\u043c \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0434\u043e\u043b\u0438 \u0448\u0438\u0440\u0438\u043d\u044b\/\u0432\u044b\u0441\u043e\u0442\u044b \u043c\u0430\u043a\u0435\u0442\u0430 (\u0432 \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u0430\u0445 \u043f\u043e \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044e \u043a \u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0443) \u0438\u043b\u0438 \u043f\u0443\u0442\u0435\u043c \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u044b\u0445 \u0438\u043b\u0438 \u0440\u0430\u0441\u0447\u0435\u0442\u043d\u044b\u0445 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u0432.<\/p>\n<p><strong>NSCollectionLayoutItem:<\/strong>\u00a0\u042d\u0442\u043e \u044f\u0447\u0435\u0439\u043a\u0430 \u043d\u0430\u0448\u0435\u0433\u043e \u043c\u0430\u043a\u0435\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u044d\u043a\u0440\u0430\u043d\u0435 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0440\u0430\u0437\u043c\u0435\u0440\u0430.<\/p>\n<p><strong>NSCollectionLayoutGroup:<\/strong>\u00a0\u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u00a0<strong>NSCollectionLayoutItem<\/strong>\u00a0\u0432 \u0433\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u044c\u043d\u043e\u0439, \u0432\u0435\u0440\u0442\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0439 \u0438\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0439 \u0444\u043e\u0440\u043c\u0430\u0445.<\/p>\n<p><strong>NSCollectionLayoutSection<\/strong>: \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0435\u043a\u0446\u0438\u0438 \u043f\u0443\u0442\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 <strong>NSCollectionLayoutGroup<\/strong>. \u0421\u0435\u043a\u0446\u0438\u0438 \u0432 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0438\u0442\u043e\u0433\u0435 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 <strong>\u0421ompositionalLayout.<\/strong><\/p>\n<p>Sections \u0438 items\u00a0\u0432\u00a0<strong>\u0421ompositionalLayout\u00a0<\/strong>\u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442\u00a0Sections \u0438 items \u043a\u043b\u0430\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0421ollectionViewDataSource. \u0413\u0440\u0443\u043f\u043f\u044b, \u043e\u0434\u043d\u0430\u043a\u043e, \u043d\u0435 \u0438\u043c\u0435\u044e\u0442 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u0430 \u0432 \u0421ollectionViewDataSource\u00a0\u0438 \u043d\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u044e\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0432 \u0432\u0438\u0434\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \/ \u044f\u0447\u0435\u0435\u043a. \u041e\u043d\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430\u0448\u0438\u0445 Items \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 Section.<\/p>\n<figure class=\"full-width\"><\/figure>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u0438 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c CollectionView c\u043e \u0441\u043a\u0440\u043e\u043b\u044f\u0449\u0438\u043c\u0438\u0441\u044f \u0440\u044f\u0434\u0430\u043c\u0438. \u041c\u044b \u0443\u0432\u0438\u0434\u0438\u043c \u043d\u0430\u0441\u043a\u043e\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e\u00a0\u0421ompositionalLayout\u00a0\u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 \u0442\u0440\u0430\u0434\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u043c, \u043a\u043e\u0433\u0434\u0430 \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u044f \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0433\u043e \u044d\u0444\u0444\u0435\u043a\u0442\u0430 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u0432\u043d\u0435\u0434\u0440\u044f\u0442\u044c\u00a0CollectionView \u0432 \u0434\u0440\u0443\u0433\u0438\u0435 CollectionView.<\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043b\u0430\u0441\u0441\u00a0ViewController, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0443 UICollectionViewDelegate:<\/p>\n<pre><code class=\"swift\">class ViewController: UIViewController, UICollectionViewDelegate {  }<\/code><\/pre>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0432 \u043d\u0435\u0433\u043e \u0434\u0432\u0430 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 dataSource \u0438 collectionView:<\/p>\n<pre><code class=\"swift\">var dataSource: UICollectionViewDiffableDataSource&lt;Int, Int>! = nil      var collectionView: UICollectionView! = nil<\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043b\u0430\u0441\u0441 \u044f\u0447\u0435\u0439\u043a\u0438 \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0439 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438:<\/p>\n<pre><code class=\"swift\">class TextCell: UICollectionViewCell {     let label = UILabel()     static let reuseIdentifier = \"text-cell-reuse-identifier\"      override init(frame: CGRect) {         super.init(frame: frame)         configure()     }     required init?(coder: NSCoder) {         fatalError(\"not implemnted\")     } }<\/code><\/pre>\n<p>\u0412 \u044d\u043a\u0441\u0442\u0435\u043d\u0448\u0435\u043d\u0435 \u0437\u0430\u0434\u0430\u0434\u0438\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0435\u0439\u043d\u0442\u044b:<\/p>\n<pre><code class=\"swift\">extension TextCell {     func configure() {         label.translatesAutoresizingMaskIntoConstraints = false         label.adjustsFontForContentSizeCategory = true         contentView.addSubview(label)         label.font = UIFont.preferredFont(forTextStyle: .caption1)         let inset = CGFloat(10)         NSLayoutConstraint.activate([             label.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: inset),             label.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -inset),             label.topAnchor.constraint(equalTo: contentView.topAnchor, constant: inset),             label.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -inset)             ])     } }<\/code><\/pre>\n<p>\u041c\u044b \u043f\u043e\u0434\u043e\u0448\u043b\u0438 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043a \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u043b\u044d\u0439\u0430\u0443\u0442\u0430. \u0412\u044b\u043d\u0435\u0441\u0435\u043c \u0435\u0433\u043e \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434:<\/p>\n<pre><code class=\"swift\">func createLayout() -> UICollectionViewLayout {         let layout = UICollectionViewCompositionalLayout {             (sectionIndex: Int, layoutEnvironment: NSCollectionLayoutEnvironment) -> NSCollectionLayoutSection? in  \/\/ \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u0435\u043c Item. \u0417\u0430\u0434\u0430\u0435\u043c \u0435\u043c\u0443 \u0448\u0438\u0440\u0438\u043d\u0443 \u0438 \u0432\u044b\u0441\u043e\u0442\u0443 \u0433\u0440\u0443\u043f\u043f\u044b,  \/\/ \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043c\u0435\u0449\u0435\u043d. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0437\u0430\u0434\u0430\u0435\u043c widthDimension \u0438  \/\/ heightDimension \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f .fractionalWidth(1.0) \u0438 .fractionalHeight(1.0) \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e. \/\/ \u0422\u0430\u043a \u0436\u0435 \u0437\u0430\u0434\u0430\u0435\u043c \u0443 Item \u043e\u0442\u0441\u0442\u0443\u043f\u044b \u0447\u0435\u0440\u0435\u0437 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e contentInsets.                      let item = NSCollectionLayoutItem(             layoutSize: NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0),                                                   heightDimension: .fractionalHeight(1.0)))             item.contentInsets = NSDirectionalEdgeInsets(top: 10, leading: 10, bottom: 10, trailing: 10)   \/\/ \u0421\u043e\u0437\u0434\u0430\u0435\u043c Group \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0433\u0430\u044e\u0442\u0441\u044f \u0433\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u044c\u043d\u043e.  \/\/ \u0417\u0430\u0434\u0430\u0435\u043c \u0435\u0439 \u0448\u0438\u0440\u0438\u043d\u0443 85% \u0448\u0438\u0440\u0438\u043d\u044b \u044d\u043a\u0440\u0430\u043d\u0430 \u0438 \u0432\u044b\u0441\u043e\u0442\u0443 40% \u0432\u044b\u0441\u043e\u0442\u044b \u044d\u043a\u0440\u0430\u043d\u0430. \/\/ \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 Group \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u0432\u044b\u0448\u0435 Item                      let containerGroup = NSCollectionLayoutGroup.horizontal(             layoutSize: NSCollectionLayoutSize(widthDimension: .fractionalWidth(0.85),                                                   heightDimension: .fractionalHeight(0.4)),             subitems: [item])              \/\/ \u0421\u043e\u0437\u0434\u0430\u0435\u043c Section, \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u044f \u0432 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0443\u044e \u0432\u044b\u0448\u0435 Group.  \/\/ \u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0441\u0435\u043a\u0446\u0438\u044f \u0438\u043c\u0435\u043b\u0430 \u0432\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u043a\u0440\u043e\u043b\u0438\u0442\u044c\u0441\u044f \u0437\u0430\u0434\u0430\u0435\u043c \u0435\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e   \/\/ orthogonalScrollingBehavior.                 let section = NSCollectionLayoutSection(group: containerGroup)         section.orthogonalScrollingBehavior = .continuous          return section      }      return layout }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0421ollectionView, \u043f\u0435\u0440\u0435\u0434\u0430\u0432 \u0432 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 \u043b\u044d\u0439\u0430\u0443\u0442, \u043a\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043d\u0430\u043c\u0438 \u043c\u0435\u0442\u043e\u0434.<\/p>\n<p>\u0412\u044b\u043d\u0435\u043c\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0438 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e \u0421ollectionView \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434.<\/p>\n<pre><code class=\"swift\"> func configureHierarchy() {         collectionView = UICollectionView(frame: view.bounds, collectionViewLayout: createLayout())         collectionView.autoresizingMask = [.flexibleWidth, .flexibleHeight]         collectionView.backgroundColor = .systemMint         view.addSubview(collectionView)         collectionView.delegate = self  }<\/code><\/pre>\n<p>\u0418 \u0432\u044b\u0437\u043e\u0432\u0435\u043c \u0435\u0433\u043e \u0432\u043e viewDidLoad.<\/p>\n<pre><code class=\"swift\"> override func viewDidLoad() {         super.viewDidLoad()          navigationItem.title = \"Scrollable rows\"         configureHierarchy()   }<\/code><\/pre>\n<p>\u041d\u0430\u043c \u043e\u0441\u0442\u0430\u043b\u0441\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0448\u0430\u0433. \u0421\u043e\u0437\u0434\u0430\u0442\u044c \u0438 \u0441\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c DataSource.<\/p>\n<pre><code class=\"swift\">func configureDataSource() {  \/\/ \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043c\u0430\u0441\u0441\u0438\u0432 \u044d\u043c\u043e\u0434\u0436\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u0432 \u044f\u0447\u0435\u0439\u043a\u0430\u0445 \u043d\u0430\u0448\u0435\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b          let emojies = [\"?\", \"?\", \"?\", \"?\", \"?\", \"?\",\"?\", \"?\", \"?\"]     \/\/ \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c  CellRegistration \u0441 \u0442\u0438\u043f\u043e\u043c \u043d\u0430\u0448\u0435\u0439 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u0439 \u044f\u0447\u0435\u0439\u043a\u0438. \u0418 \u0441\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u0443\u0435\u043c \u043d\u0430\u0448\u0443 \u044f\u0447\u0435\u0439\u043a\u0443.             let cellRegistration = UICollectionView.CellRegistration&lt;TextCell, Int> { (cell, indexPath, identifier) in                          cell.label.text = \"\\(emojies[indexPath.item])\"             cell.contentView.backgroundColor = .systemCyan             cell.contentView.layer.borderColor = UIColor.black.cgColor             cell.contentView.layer.borderWidth = 1             cell.contentView.layer.cornerRadius = 8             cell.label.textAlignment = .center             cell.label.font = UIFont.systemFont(ofSize: 150)         }         \/\/ \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c  UICollectionViewDiffableDataSource \u043f\u0435\u0440\u0435\u0434\u0430\u0432 \u0432 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 collectionView.           dataSource = UICollectionViewDiffableDataSource&lt;Int, Int>(collectionView: collectionView) {             (collectionView: UICollectionView, indexPath: IndexPath, identifier: Int) -> UICollectionViewCell? in                          return collectionView.dequeueConfiguredReusableCell(using: cellRegistration, for: indexPath, item: identifier)         }     \/\/ \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c  NSDiffableDataSourceSnapshot \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0443\u043a\u0430\u0436\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0435\u043a\u0446\u0438\u0439  \/\/ \u0438 \u0430\u0439\u0442\u0435\u043c\u043e\u0432 \u0432 \u0441\u0435\u043a\u0446\u0438\u0438. \/\/ NSDiffableDataSourceSnapshot \u2014 \u044d\u0442\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u043e view  \/\/ \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u0438.  \/\/ DiffableDataSource \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 Snapshot \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445  \/\/ \u0434\u043b\u044f \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439 \u0438 \u0442\u0430\u0431\u043b\u0438\u0446. \u041c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c Snapshot \u0434\u043b\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438  \/\/ \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445, \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c\u044b\u0445 \u0432 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438,  \/\/ \u043c\u044b \u0442\u0430\u043a \u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 Snapshot \u0434\u043b\u044f \u043e\u0442\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0432 \u0434\u0430\u043d\u043d\u044b\u0445,  \/\/ \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c\u044b\u0445 \u0432 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438. \/\/ \u0414\u0430\u043d\u043d\u044b\u0435 \u0432 Snapshot \u0441\u043e\u0441\u0442\u043e\u044f\u0442 \u0438\u0437 sections  \u0438 items, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c, \/\/ \u0432 \u0442\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0441\u0430\u043c\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c.  \/\/ \u041c\u044b \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c \u0432\u0438\u0434 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044f, \u0443\u0434\u0430\u043b\u044f\u044f \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u044f  \/\/ sections \u0438 items.            var snapshot = NSDiffableDataSourceSnapshot&lt;Int, Int>()         var identifierOffset = 0         let itemsPerSection = 9         for section in 0..&lt;5 {             snapshot.appendSections([section])             let maxIdentifier = identifierOffset + itemsPerSection             snapshot.appendItems(Array(identifierOffset..&lt;maxIdentifier))             identifierOffset += itemsPerSection         }         dataSource.apply(snapshot, animatingDifferences: false)     }<\/code><\/pre>\n<p>\u0412\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043d\u0430\u0448 \u043c\u0435\u0442\u043e\u0434 \u0432\u043e viewDidLoad.<\/p>\n<pre><code class=\"swift\"> override func viewDidLoad() {         super.viewDidLoad()         navigationItem.title = \"Scrollable rows\"         configureHierarchy()         configureDataSource()     }<\/code><\/pre>\n<p>\u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"swift\">import UIKit  class ViewController: UIViewController, UICollectionViewDelegate {          var dataSource: UICollectionViewDiffableDataSource&lt;Int, Int>! = nil     var collectionView: UICollectionView! = nil      override func viewDidLoad() {         super.viewDidLoad()         navigationItem.title = \"Scrollable rows\"         configureHierarchy()         configureDataSource()     }          func configureHierarchy() {         collectionView = UICollectionView(frame: view.bounds, collectionViewLayout: createLayout())         collectionView.autoresizingMask = [.flexibleWidth, .flexibleHeight]         collectionView.backgroundColor = .systemMint         view.addSubview(collectionView)         collectionView.delegate = self     }          func configureDataSource() {         let emojies = [\"?\", \"?\", \"?\", \"?\", \"?\", \"?\",\"?\", \"?\", \"?\"]                  let cellRegistration = UICollectionView.CellRegistration&lt;TextCell, Int> { (cell, indexPath, identifier) in                          cell.label.text = \"\\(emojies[indexPath.item])\"             cell.contentView.backgroundColor = .systemCyan             cell.contentView.layer.borderColor = UIColor.black.cgColor<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-348656","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/348656","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=348656"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/348656\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=348656"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=348656"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=348656"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}