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
590
作って学ぶ! 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.3k
Other Decks in Programming
See All in Programming
Folding Cheat Sheet #1
philipschwarz
PRO
0
210
コードレビューで学ぶ!Kotlinオブジェクト指向デザインパターン
akkie76
2
170
脱・初心者!脱・マネコン!AWS CDKを使ってみませんか!?
har1101
0
300
本格ローグライク制作にEbitengineを選んでみた
nagainaganawa
0
290
スクラムチームと認知負荷 - ニフティのスクラムトーク Vol2. / NIFTY Tech Talk #18
niftycorp
PRO
1
120
大規模Reactアプリのリアーキテクチャ~8万行のTanStack Query移行の軌跡~
kj455
3
420
1인 개발자로 행복하게 살기 - GDG 송도 헬로월드 2024
benjaminkim
1
5.6k
受託開発でGitLab CI を活用していく
xiombatsg
1
270
スクラムガイドのスプリントレトロスペクティブを改めて読みかえしてみた / Re-reading the Sprint Retrospective Section in the Scrum Guide
mackey0225
3
320
今の SmartHR にエンジニアで入社するとどうなるの?
daisukeshinoku
5
4.6k
What We Can Learn From OSS
inouehi
0
400
Java 22 Overview
kishida
1
160
Featured
See All Featured
The Cult of Friendly URLs
andyhume
73
5.7k
YesSQL, Process and Tooling at Scale
rocio
162
13k
Clear Off the Table
cherdarchuk
82
310k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
320
20k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
13
1.5k
GraphQLの誤解/rethinking-graphql
sonatard
49
9.2k
Fantastic passwords and where to find them - at NoRuKo
philnash
36
2.5k
A Tale of Four Properties
chriscoyier
150
22k
How to train your dragon (web standard)
notwaldorf
71
5.1k
Code Review Best Practice
trishagee
54
15k
Designing for humans not robots
tammielis
247
25k
What's new in Ruby 2.0
geeforr
336
31k
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