Closed4

【Swift】CollectionView 0->1

yoshitakayoshitaka

画面表示に自動スクロールさせる

rxViewDidAppear.subscribe(onNext: { [weak self] _ in
            guard let self = self else { return }
            guard let index = self.viewModel.scrollToSelectedItems.value else { return }
            self.collectionView.scrollToItem(at: index, at: .top, animated: true)
        }).disposed(by: disposeBag)

スクロールさせたい場所indexが分かれば、viewDidAppearにcollectionView.scrollToItem(at: index, at: .top, animated: true)を入れれば一発だった。

少し注意なのは、viewdidload,viewwillappearだとまだコレクションビューが描画されていないので、スクロールはされないところ

yoshitakayoshitaka

WWDC 2020

  • Advances in diffable data sources
    これも参考になる
  • Advances in UICollectionView
    これが総括
  • Modern cell configuration
    defaultContentConfiguration()
  • Lists in UICollectionView
    let configuration = UICollectionLayoutListConfiguration(appearance: .insetGrouped)
    let layout = UICollectionViewCompositionalLayout.list(using: configuration)

WWDC 2019

  • Advances in Collection View Layout
    NSCollectionLayoutSize
    NSCollectionLayoutItem
    NSCollectionLayoutGroup
    NSCollectionLayoutSection
  • Advances in UI Data Sources
    UICollectionViewDiffableDataSource
    UITableViewDiffableDataSource
    NSCollectionViewDiffableDataSource
    NSDiffableDataSourceSnapshot

WWDC 2018

  • A Tour of UICollectionView
    UICollectionViewFlowLayoutでできることの説明
  • Using Collections Effectively
    Collectionの..firstslice
このスクラップは2021/05/07にクローズされました