{"id":352676,"date":"2024-05-20T22:13:17","date_gmt":"2024-05-20T22:13:17","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=352676"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2024-05-20T22:13:17","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=352676","title":{"rendered":"<span>UICollectionView \u0432\u043d\u0443\u0442\u0440\u0438 UICollectionView \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043d\u043e<\/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<p>\u041a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043f\u0440\u0438 \u043f\u043e\u0438\u0441\u043a\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043a\u0430\u0441\u0430\u044e\u0449\u0435\u0439\u0441\u044f CollectionView \u044f \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u044e\u0441\u044c \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0430 \u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0441\u0442\u043e\u0440\u0438\u0431\u043e\u0440\u0434\u043e\u0432, \u043d\u043e \u0443\u043c\u0435\u043d\u0438\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043d\u043e \u044d\u0442\u043e, \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c, \u043f\u043b\u044e\u0441 \u043a \u043a\u0430\u0440\u043c\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u043d\u0435 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0442\u0435\u043c \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 CollectionView, \u0432 \u043a\u043e\u043d\u0446\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u043f\u0440\u0438\u043a\u0440\u0435\u043f\u043b\u044e \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0433\u0438\u0442\u0445\u0430\u0431.<\/p>\n<p>\u0427\u0442\u043e \u0434\u043e\u043b\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c\u0441\u044f:<\/p>\n<figure class=\"bordered full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/613\/c1b\/bcb\/613c1bbcb926627a58e70b4c39746204.png\" width=\"1624\" height=\"1042\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/613\/c1b\/bcb\/613c1bbcb926627a58e70b4c39746204.png\"\/><\/figure>\n<p>\u041d\u0443 \u0447\u0442\u043e, \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c, \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f \u0441 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0435\u0439 \u0432\u043e ViewController<\/p>\n<ul>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0435\u043c collectionView<\/p>\n<\/li>\n<li>\n<p>\u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u0430 \u0432\u044c\u044e<\/p>\n<\/li>\n<li>\n<p>\u0432\u044b\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0435\u0439\u043d\u0442\u044b<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"swift\">class ViewController: UIViewController {          lazy var collectionView: UICollectionView = {         let layout = UICollectionViewFlowLayout()         let collection = UICollectionView(frame: .zero, collectionViewLayout: layout)         collection.backgroundColor = .systemGreen         collection.translatesAutoresizingMaskIntoConstraints = false         return collection     }()      override func viewDidLoad() {         super.viewDidLoad()         setupViews()         setupConstraints()     }      func setupViews() {         view.addSubview(collectionView)     }          func setupConstraints() {         let safeArea = view.safeAreaLayoutGuide                  NSLayoutConstraint.activate([             collectionView.leadingAnchor.constraint(equalTo: view.leadingAnchor),             collectionView.trailingAnchor.constraint(equalTo: view.trailingAnchor),             collectionView.topAnchor.constraint(equalTo: safeArea.topAnchor, constant: 16),             collectionView.bottomAnchor.constraint(equalTo: safeArea.bottomAnchor, constant: -16)         ])     } }<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c &#8212; \u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u0432\u0441\u0435 \u043f\u043e\u044f\u0432\u0438\u043b\u043e\u0441\u044c<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/2a7\/dd3\/619\/2a7dd3619f9287f8fac2e36630123dfc.png\" width=\"1282\" height=\"850\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/2a7\/dd3\/619\/2a7dd3619f9287f8fac2e36630123dfc.png\"\/><\/figure>\n<p>\u0414\u0430\u043b\u0435\u0435, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u044f\u0447\u0435\u0439\u043a\u0443-\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440, \u0432 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u043f\u043e\u043b\u043e\u0436\u0438\u043c \u0435\u0449\u0435 \u043e\u0434\u0438\u043d CollectionView, \u0432\u0441\u0435 \u0434\u0435\u043b\u0430\u0435\u043c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e<\/p>\n<ul>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e<\/p>\n<\/li>\n<li>\n<p>\u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0433\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u044c\u043d\u0443\u044e \u043f\u0440\u043e\u043a\u0440\u0443\u0442\u043a\u0443<\/p>\n<\/li>\n<li>\n<p>\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0440\u0430\u0437\u043c\u0435\u0440\u044b<\/p>\n<\/li>\n<li>\n<p>\u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e \u0432 \u044f\u0447\u0435\u0439\u043a\u0443<\/p>\n<\/li>\n<li>\n<p>\u0432\u044b\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0435\u0439\u043d\u0442\u044b<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"swift\">class CollectionContainerViewCell: UICollectionViewCell {          static let id = \"CollectionContainerViewCell\"          lazy var collectionView: UICollectionView = {         let layout = UICollectionViewFlowLayout()         layout.scrollDirection = .horizontal         layout.itemSize = CGSize(width: 170, height: 170)         let collection = UICollectionView(frame: .zero, collectionViewLayout: layout)         collection.backgroundColor = .systemYellow         collection.translatesAutoresizingMaskIntoConstraints = false         return collection     }()          override init(frame: CGRect) {         super.init(frame: frame)         setupViews()         setupConstraints()     }          required init?(coder: NSCoder) {         fatalError(\"init(coder:) has not been implemented\")     }          func setupViews() {         contentView.addSubview(collectionView)     }          func setupConstraints() {         NSLayoutConstraint.activate([             collectionView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),             collectionView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor),             collectionView.topAnchor.constraint(equalTo: contentView.topAnchor),             collectionView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor)         ])     } }<\/code><\/pre>\n<p>\u0413\u043e\u0442\u043e\u0432\u043e, \u0442\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u044d\u0442\u043e\u0442 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0432 \u043d\u0430\u0448\u0443 \u043e\u0441\u043d\u043e\u0432\u043d\u0443\u044e \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e <\/p>\n<ul>\n<li>\n<p>\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u043c \u044f\u0447\u0435\u0439\u043a\u0443 \u0432 collectionView<\/p>\n<\/li>\n<li>\n<p>\u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u044b<\/p>\n<\/li>\n<li>\n<p>\u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0440\u0430\u0437\u043c\u0435\u0440\u044b \u043b\u044d\u0439\u0430\u0443\u0442\u0430, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0435\u043a\u0446\u0438\u0439\/\u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u0441\u0435\u043a\u0446\u0438\u0438<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"swift\">class ViewController: UIViewController {          lazy var collectionView: UICollectionView = {         let layout = UICollectionViewFlowLayout()         let collection = UICollectionView(frame: .zero, collectionViewLayout: layout)         collection.backgroundColor = .systemGreen         collection.translatesAutoresizingMaskIntoConstraints = false                  collection.register(CollectionContainerViewCell.self, forCellWithReuseIdentifier: CollectionContainerViewCell.id)         collection.delegate = self         collection.dataSource = self                  return collection     }()      override func viewDidLoad() {         super.viewDidLoad()         setupViews()         setupConstraints()     }      func setupViews() {         view.addSubview(collectionView)     }          func setupConstraints() {         let safeArea = view.safeAreaLayoutGuide                  NSLayoutConstraint.activate([             collectionView.leadingAnchor.constraint(equalTo: view.leadingAnchor),             collectionView.trailingAnchor.constraint(equalTo: view.trailingAnchor),             collectionView.topAnchor.constraint(equalTo: safeArea.topAnchor, constant: 16),             collectionView.bottomAnchor.constraint(equalTo: safeArea.bottomAnchor, constant: -16)         ])     } }  extension ViewController: UICollectionViewDelegate {          func numberOfSections(in collectionView: UICollectionView) -> Int {         return 3     } }  extension ViewController: UICollectionViewDataSource {     func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {         return 7     }          func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {         let cell = collectionView.dequeueReusableCell(withReuseIdentifier: CollectionContainerViewCell.id, for: indexPath) as! CollectionContainerViewCell         return cell     } }  extension ViewController: UICollectionViewDelegateFlowLayout {          func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {         switch indexPath.section {         case 0: return CGSize(width: UIScreen.main.bounds.width, height: 200)         case 1: return CGSize(width: UIScreen.main.bounds.width, height: 200)         case 2: return CGSize(width: UIScreen.main.bounds.width, height: 200)         default: return CGSize(width: 0, height: 0)         }     } }<\/code><\/pre>\n<p>\u0421\u043c\u043e\u0442\u0440\u0438\u043c \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c &#8212; \u0432\u0441\u0435 \u043a\u0430\u043a \u0438 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e86\/18a\/003\/e8618a003e01e0845ed19e2628fe64c1.png\" width=\"1370\" height=\"846\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e86\/18a\/003\/e8618a003e01e0845ed19e2628fe64c1.png\"\/><\/figure>\n<p>\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c, \u043d\u0430\u043c \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u0443\u044e \u044f\u0447\u0435\u0439\u043a\u0443 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u043f\u043e\u043b\u043e\u0436\u0438\u043c \u0432 \u0440\u0430\u043d\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440<\/p>\n<pre><code class=\"swift\">class InnerCollectionViewCell: UICollectionViewCell {          static let id = \"InnerCollectionViewCell\"          override init(frame: CGRect) {         super.init(frame: frame)         setupViews()         setupConstraints()     }          required init?(coder: NSCoder) {         fatalError(\"init(coder:) has not been implemented\")     }          func setupViews() {         contentView.backgroundColor = .systemRed              }          func setupConstraints() {      } }<\/code><\/pre>\n<p>\u0418 \u0442\u0435\u043f\u0435\u0440\u044c, \u043d\u0430\u043a\u043e\u043d\u0435\u0446-\u0442\u043e \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0435\u0435 \u0432 \u043d\u0430\u0448 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440, \u0432\u0441\u0435 \u043f\u043e \u043a\u043b\u0430\u0441\u0441\u0438\u043a\u0435: \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u043c, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u044b, \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043e\u0442\u0441\u0442\u0443\u043f\u044b, \u043a\u0430\u0441\u0442\u043e\u043c\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f\u043c\u0438<\/p>\n<pre><code class=\"swift\">class CollectionContainerViewCell: UICollectionViewCell {          static let id = \"CollectionContainerViewCell\"          lazy var collectionView: UICollectionView = {         let layout = UICollectionViewFlowLayout()         layout.scrollDirection = .horizontal         layout.itemSize = CGSize(width: 170, height: 170)         let collection = UICollectionView(frame: .zero, collectionViewLayout: layout)         collection.backgroundColor = .systemYellow         collection.translatesAutoresizingMaskIntoConstraints = false                  collection.register(InnerCollectionViewCell.self, forCellWithReuseIdentifier: InnerCollectionViewCell.id)         collection.delegate = self         collection.dataSource = self                  return collection     }()          override init(frame: CGRect) {         super.init(frame: frame)         setupViews()         setupConstraints()     }          required init?(coder: NSCoder) {         fatalError(\"init(coder:) has not been implemented\")     }          func setupViews() {         contentView.addSubview(collectionView)     }          func setupConstraints() {         NSLayoutConstraint.activate([             collectionView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),             collectionView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor),             collectionView.topAnchor.constraint(equalTo: contentView.topAnchor),             collectionView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor)         ])     } }  extension CollectionContainerViewCell: UICollectionViewDelegate, UICollectionViewDataSource {          func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {         return 7     }          func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {         let cell = collectionView.dequeueReusableCell(withReuseIdentifier: InnerCollectionViewCell.id, for: indexPath) as! InnerCollectionViewCell         return cell     } }  extension CollectionContainerViewCell: UICollectionViewDelegateFlowLayout {          func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {         return UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)     } }<\/code><\/pre>\n<p>\u0421\u043c\u043e\u0442\u0440\u0438\u043c \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c <\/p>\n<figure class=\"bordered\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3ec\/613\/d90\/3ec613d9078d6d32cbc0141a39f0d7fc.gif\" width=\"358\" height=\"748\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3ec\/613\/d90\/3ec613d9078d6d32cbc0141a39f0d7fc.gif\"\/><\/figure>\n<p><a href=\"https:\/\/github.com\/anzmax\/collection-view-challenge\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/anzmax\/collection-view-challenge<\/a><\/p>\n<\/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\/755774\/\"> https:\/\/habr.com\/ru\/articles\/755774\/<\/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<p>\u041a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043f\u0440\u0438 \u043f\u043e\u0438\u0441\u043a\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043a\u0430\u0441\u0430\u044e\u0449\u0435\u0439\u0441\u044f CollectionView \u044f \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u044e\u0441\u044c \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0430 \u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0441\u0442\u043e\u0440\u0438\u0431\u043e\u0440\u0434\u043e\u0432, \u043d\u043e \u0443\u043c\u0435\u043d\u0438\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043d\u043e \u044d\u0442\u043e, \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c, \u043f\u043b\u044e\u0441 \u043a \u043a\u0430\u0440\u043c\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u043d\u0435 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0442\u0435\u043c \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 CollectionView, \u0432 \u043a\u043e\u043d\u0446\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u043f\u0440\u0438\u043a\u0440\u0435\u043f\u043b\u044e \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0433\u0438\u0442\u0445\u0430\u0431.<\/p>\n<p>\u0427\u0442\u043e \u0434\u043e\u043b\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c\u0441\u044f:<\/p>\n<figure class=\"bordered full-width\"><\/figure>\n<p>\u041d\u0443 \u0447\u0442\u043e, \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c, \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f \u0441 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0435\u0439 \u0432\u043e ViewController<\/p>\n<ul>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0435\u043c collectionView<\/p>\n<\/li>\n<li>\n<p>\u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u0430 \u0432\u044c\u044e<\/p>\n<\/li>\n<li>\n<p>\u0432\u044b\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0435\u0439\u043d\u0442\u044b<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"swift\">class ViewController: UIViewController {          lazy var collectionView: UICollectionView = {         let layout = UICollectionViewFlowLayout()         let collection = UICollectionView(frame: .zero, collectionViewLayout: layout)         collection.backgroundColor = .systemGreen         collection.translatesAutoresizingMaskIntoConstraints = false         return collection     }()      override func viewDidLoad() {         super.viewDidLoad()         setupViews()         setupConstraints()     }      func setupViews() {         view.addSubview(collectionView)     }          func setupConstraints() {         let safeArea = view.safeAreaLayoutGuide                  NSLayoutConstraint.activate([             collectionView.leadingAnchor.constraint(equalTo: view.leadingAnchor),             collectionView.trailingAnchor.constraint(equalTo: view.trailingAnchor),             collectionView.topAnchor.constraint(equalTo: safeArea.topAnchor, constant: 16),             collectionView.bottomAnchor.constraint(equalTo: safeArea.bottomAnchor, constant: -16)         ])     } }<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c &#8212; \u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u0432\u0441\u0435 \u043f\u043e\u044f\u0432\u0438\u043b\u043e\u0441\u044c<\/p>\n<figure class=\"full-width\"><\/figure>\n<p>\u0414\u0430\u043b\u0435\u0435, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u044f\u0447\u0435\u0439\u043a\u0443-\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440, \u0432 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u043f\u043e\u043b\u043e\u0436\u0438\u043c \u0435\u0449\u0435 \u043e\u0434\u0438\u043d CollectionView, \u0432\u0441\u0435 \u0434\u0435\u043b\u0430\u0435\u043c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e<\/p>\n<ul>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e<\/p>\n<\/li>\n<li>\n<p>\u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0433\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u044c\u043d\u0443\u044e \u043f\u0440\u043e\u043a\u0440\u0443\u0442\u043a\u0443<\/p>\n<\/li>\n<li>\n<p>\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0440\u0430\u0437\u043c\u0435\u0440\u044b<\/p>\n<\/li>\n<li>\n<p>\u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e \u0432 \u044f\u0447\u0435\u0439\u043a\u0443<\/p>\n<\/li>\n<li>\n<p>\u0432\u044b\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0435\u0439\u043d\u0442\u044b<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"swift\">class CollectionContainerViewCell: UICollectionViewCell {          static let id = \"CollectionContainerViewCell\"          lazy var collectionView: UICollectionView = {         let layout = UICollectionViewFlowLayout()         layout.scrollDirection = .horizontal         layout.itemSize = CGSize(width: 170, height: 170)         let collection = UICollectionView(frame: .zero, collectionViewLayout: layout)         collection.backgroundColor = .systemYellow         collection.translatesAutoresizingMaskIntoConstraints = false         return collection     }()          override init(frame: CGRect) {         super.init(frame: frame)         setupViews()         setupConstraints()     }          required init?(coder: NSCoder) {         fatalError(\"init(coder:) has not been implemented\")     }          func setupViews() {         contentView.addSubview(collectionView)     }          func setupConstraints() {         NSLayoutConstraint.activate([             collectionView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),             collectionView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor),             collectionView.topAnchor.constraint(equalTo: contentView.topAnchor),             collectionView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor)         ])     } }<\/code><\/pre>\n<p>\u0413\u043e\u0442\u043e\u0432\u043e, \u0442\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u044d\u0442\u043e\u0442 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0432 \u043d\u0430\u0448\u0443 \u043e\u0441\u043d\u043e\u0432\u043d\u0443\u044e \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e <\/p>\n<ul>\n<li>\n<p>\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u043c \u044f\u0447\u0435\u0439\u043a\u0443 \u0432 collectionView<\/p>\n<\/li>\n<li>\n<p>\u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u044b<\/p>\n<\/li>\n<li>\n<p>\u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0440\u0430\u0437\u043c\u0435\u0440\u044b \u043b\u044d\u0439\u0430\u0443\u0442\u0430, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0435\u043a\u0446\u0438\u0439\/\u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u0441\u0435\u043a\u0446\u0438\u0438<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"swift\">class ViewController: UIViewController {          lazy var collectionView: UICollectionView = {         let layout = UICollectionViewFlowLayout()         let collection = UICollectionView(frame: .zero, collectionViewLayout: layout)         collection.backgroundColor = .systemGreen         collection.translatesAutoresizingMaskIntoConstraints = false                  collection.register(CollectionContainerViewCell.self, forCellWithReuseIdentifier: CollectionContainerViewCell.id)         collection.delegate = self         collection.dataSource = self                  return collection     }()      override func viewDidLoad() {         super.viewDidLoad()         setupViews()         setupConstraints()     }      func setupViews() {         view.addSubview(collectionView)     }          func setupConstraints() {         let safeArea = view.safeAreaLayoutGuide                  NSLayoutConstraint.activate([             collectionView.leadingAnchor.constraint(equalTo: view.leadingAnchor),             collectionView.trailingAnchor.constraint(equalTo: view.trailingAnchor),             collectionView.topAnchor.constraint(equalTo: safeArea.topAnchor, constant: 16),             collectionView.bottomAnchor.constraint(equalTo: safeArea.bottomAnchor, constant: -16)         ])     } }  extension ViewController: UICollectionViewDelegate {          func numberOfSections(in collectionView: UICollectionView) -> Int {         return 3     } }  extension ViewController: UICollectionViewDataSource {     func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {         return 7     }          func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {         let cell = collectionView.dequeueReusableCell(withReuseIdentifier: CollectionContainerViewCell.id, for: indexPath) as! CollectionContainerViewCell         return cell     } }  extension ViewController: UICollectionViewDelegateFlowLayout {          func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {         switch indexPath.section {         case 0: return CGSize(width: UIScreen.main.bounds.width, height: 200)         case 1: return CGSize(width: UIScreen.main.bounds.width, height: 200)         case 2: return CGSize(width: UIScreen.main.bounds.width, height: 200)         default: return CGSize(width: 0, height: 0)         }     } }<\/code><\/pre>\n<p>\u0421\u043c\u043e\u0442\u0440\u0438\u043c \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c &#8212; \u0432\u0441\u0435 \u043a\u0430\u043a \u0438 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c<\/p>\n<figure class=\"full-width\"><\/figure>\n<p>\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c, \u043d\u0430\u043c \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u0443\u044e \u044f\u0447\u0435\u0439\u043a\u0443 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u043f\u043e\u043b\u043e\u0436\u0438\u043c \u0432 \u0440\u0430\u043d\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440<\/p>\n<pre><code class=\"swift\">class InnerCollectionViewCell: UICollectionViewCell {          static let id = \"InnerCollectionViewCell\"          override init(frame: CGRect) {         super.init(frame: frame)         setupViews()         setupConstraints()     }          required init?(coder: NSCoder) {         fatalError(\"init(coder:) has not been implemented\")     }          func setupViews() {         contentView.backgroundColor = .systemRed              }          func setupConstraints() {      } }<\/code><\/pre>\n<p>\u0418 \u0442\u0435\u043f\u0435\u0440\u044c, \u043d\u0430\u043a\u043e\u043d\u0435\u0446-\u0442\u043e \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0435\u0435 \u0432 \u043d\u0430\u0448 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440, \u0432\u0441\u0435 \u043f\u043e \u043a\u043b\u0430\u0441\u0441\u0438\u043a\u0435: \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u043c, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u044b, \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043e\u0442\u0441\u0442\u0443\u043f\u044b, \u043a\u0430\u0441\u0442\u043e\u043c\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f\u043c\u0438<\/p>\n<pre><code class=\"swift\">class CollectionContainerViewCell: UICollectionViewCell {          static let id = \"CollectionContainerViewCell\"          lazy var collectionView: UICollectionView = {         let layout = UICollectionViewFlowLayout()         layout.scrollDirection = .horizontal         layout.itemSize = CGSize(width: 170, height: 170)         let collection = UICollectionView(frame: .zero, collectionViewLayout: layout)         collection.backgroundColor = .systemYellow         collection.translatesAutoresizingMaskIntoConstraints = false                  collection.register(InnerCollectionViewCell.self, forCellWithReuseIdentifier: InnerCollectionViewCell.id)         collection.delegate = self         collection.dataSource = self                  return collection     }()          override init(frame: CGRect) {         super.init(frame: frame)         setupViews()         setupConstraints()     }          required init?(coder: NSCoder) {         fatalError(\"init(coder:) has not been implemented\")     }          func setupViews() {         contentView.addSubview(collectionView)     }          func setupConstraints() {         NSLayoutConstraint.activate([             collectionView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),             collectionView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor),             collectionView.topAnchor.constraint(equalTo: contentView.topAnchor),             collectionView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor)         ])     } }  extension CollectionContainerViewCell: UICollectionViewDelegate, UICollectionViewDataSource {          func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {         return 7     }          func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {         let cell = collectionView.dequeueReusableCell(withReuseIdentifier: InnerCollectionViewCell.id, for: indexPath) as! InnerCollectionViewCell         return cell     } }  extension CollectionContainerViewCell: UICollectionViewDelegateFlowLayout {          func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {         return UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)     } }<\/code><\/pre>\n<p>\u0421\u043c\u043e\u0442\u0440\u0438\u043c \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c <\/p>\n<figure class=\"bordered\"><\/figure>\n<p><a href=\"https:\/\/github.com\/anzmax\/collection-view-challenge\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/anzmax\/collection-view-challenge<\/a><\/p>\n<\/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\/755774\/\"> https:\/\/habr.com\/ru\/articles\/755774\/<\/a><br \/><\/br><\/br><\/p>\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-352676","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/352676","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=352676"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/352676\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=352676"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=352676"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=352676"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}