Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
作って学ぶ! CollectionViewLayoutの変化
Search
rihitenLab
September 29, 2019
Programming
1
700
作って学ぶ! CollectionViewLayoutの変化
下記勉強会で使用した資料の公開版です
【YUMEMI.swift #3 ~俺/私がやったiOS 13対応~】
https://yumemi.connpass.com/event/142608/
rihitenLab
September 29, 2019
Tweet
Share
More Decks by rihitenLab
See All by rihitenLab
iOSエンジニアのためのロードマップ
rihitenlab
3
1.5k
Other Decks in Programming
See All in Programming
第9回 情シス転職ミートアップ 株式会社IVRy(アイブリー)の紹介
ivry_presentationmaterials
1
260
Is Xcode slowly dying out in 2025?
uetyo
1
240
地方に住むエンジニアの残酷な現実とキャリア論
ichimichi
5
1.5k
Benchmark
sysong
0
280
Select API from Kotlin Coroutine
jmatsu
1
210
生成AIコーディングとの向き合い方、AIと共創するという考え方 / How to deal with generative AI coding and the concept of co-creating with AI
seike460
PRO
1
350
Blazing Fast UI Development with Compose Hot Reload (droidcon New York 2025)
zsmb
1
280
AIコーディング道場勉強会#2 君(エンジニア)たちはどう生きるか
misakiotb
1
270
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
50
32k
dbt民主化とLLMによる開発ブースト ~ AI Readyな分析サイクルを目指して ~
yoshyum
2
240
設計やレビューに悩んでいるPHPerに贈る、クリーンなオブジェクト設計の指針たち
panda_program
6
1.8k
WebViewの現在地 - SwiftUI時代のWebKit - / The Current State Of WebView
marcy731
0
110
Featured
See All Featured
YesSQL, Process and Tooling at Scale
rocio
173
14k
Art, The Web, and Tiny UX
lynnandtonic
299
21k
Making Projects Easy
brettharned
116
6.3k
Fantastic passwords and where to find them - at NoRuKo
philnash
51
3.3k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.7k
Into the Great Unknown - MozCon
thekraken
39
1.9k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
252
21k
Build The Right Thing And Hit Your Dates
maggiecrowley
36
2.8k
Done Done
chrislema
184
16k
Java REST API Framework Comparison - PWX 2021
mraible
31
8.7k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
16k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Transcript
作って学ぶ! CollectionViewLayoutの変化
iOS12までのCollectionView UICollectionView FlowLayout つかいにくくない?
例えば... AppStore風のこんなレイアウト... UICollectionViewFlowLayoutなら どう作る?
例えば... UITableView UITableViewHeader UITableViewHeader UITableViewCell UICollectionView(Tag:1) UICollectionViewCell UITableViewCell UICollectionView(Tag:2) UICollectionViewCell
UICollectionViewCell UICollectionViewCell CollectionView in TableViewで実現 しかしこの方法には問題が・・・ - 実データとレイアウト上のデータのマッチ ングが直感的ではない - 左右に次のアイテムが表示される レイアウトを実現するにはさらに 一工夫いる (scrollViewWillEndDraggingで 停止位置を計算など) - Cellのサイズ計算が面倒臭い etc.
例えば... どんどん複雑化していく レイアウトに対応することが難し くなってきている
そこで登場! Compositional Layouts
Compositional Layoutsとは? 以下の方法でレイアウトを構成する CollectionViewの新しいレイアウト - 小さいLayoutをGroup化する - Group化の繰り返しで大きなレイアウトを 構成する
Compositional Layoutsとは? どういうこと?
Compositional Layoutsとは? Layout Section Group Item Group Item Item Section
Group - Layout:レイアウトの全体 複数のセクションを内包する - Section:セクションのレイアウト 1つのGroupを内包する - Group :Itemのレイアウト 複数のGroupまたはItemを 内包する - Item:CollectionViewCell 実データと対応する
Compositional Layoutsの便利機能 NSCollectionLayoutSize - fractionalWidth, fractionalHeight 自分を内包しているLayoutのサイズとの比率でサイズ を指定する - absolute
ポイントでサイズを指定する - estimated ポイントでサイズを指定するが、優先される制約が ある場合はそのサイズになる
Compositional Layoutsの便利機能 Group(width: fractionalWidth(1.0), height: fractionalHeight(1.0)) Item(width: fractionalWidth(0.8), height: fractionalHeight(0.4))
Group(width: fractionalWidth(0.8), height: fractionalHeight(0.4)) Item (width: fractionalWidth(0.4), height: fractionalHeight(1.0)) Item (width: fractionalWidth(0.4), height: fractionalHeight(1.0)) こんな感じでいい感じにサイズを調整できる
Compositional Layoutsの便利機能 orthogonalScrollingBehavior Sectionのパラメータで、指定するとSection内のアイテム が縦に追加されず、横スクロールで表示される - .continuous Section内で横スクロールされる - .continuousGroupLeadingBoundary
Section内で横スクロールされ、 Groupの左端がSectionの左端に揃うように スクロールが止まる
Compositional Layoutsの便利機能 続き - .paging Section内で横スクロールされ、 画面に表示されている部分単位でpagingされる - .groupPaging Section内で横スクロールされ、
GroupとSectionの左端が揃うようにPagingされる - .groupPagingCentered Section内で横スクロールされ、 GroupがセンタリングされるようにPagingされる
Compositional LayoutsでAppStore風のレイアウト を作る Group (width: fractionalWidth(1.0), height: fractionalHeight(1.0)) Item(width: fractionalWidth(0.8),
height: fractionalHeight(0.8)) 1.下の二つのGroupを用意する Group (width: fractionalWidth(1.0), height: fractionalHeight(1.0)) Item(width: fractionalWidth(0.8), height: fractionalHeight(0.3)) Item(width: fractionalWidth(0.8), height: fractionalHeight(0.3)) Item(width: fractionalWidth(0.8), height: fractionalHeight(0.3))
Compositional LayoutsでAppStore風のレイアウト を作る 2.各セクションに1.で作ったレイアウトのうち使いたい ものを設定する 3.すべてのSectionに下の設定をする section.orthogonalScrollingBehavior = .groupPagingCentered
Compositional LayoutsでAppStore風のレイアウト を作る これだけ!
まとめ - iOS13以降では複雑なレイアウトを 組みやすくなる - CollectionViewFlowLayoutの疲弊から みんなで脱却しよう!
おまけ 今回DEMOのために作成したソースを Githubで公開しています。 もしよければ参考にしてください! マサカリも大歓迎です! https://github.com/rihitenLab/AppStore LikeLayout