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
SwiftUI Layout
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Mike Apurin
June 27, 2022
Technology
880
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
SwiftUI Layout
Mike Apurin
June 27, 2022
More Decks by Mike Apurin
See All by Mike Apurin
iOSDC 2024
auramagi
3
1.5k
SwiftUIに最適のアーキテクチャ
auramagi
2
950
SwiftUIとUIKitを仲良くさせる
auramagi
3
6.1k
SwiftUIでUIViewを使うときのレイアウト処理 / Layout process when using UIKit view in SwiftUI
auramagi
0
760
Other Decks in Technology
See All in Technology
白金鉱業Meetup_Vol.24_「AIエージェントは分けるほど良い」は本当か? / Is it true that “the more you divide AI agents, the better”?
brainpadpr
1
390
自宅LLMの話
jacopen
1
590
Claude Codeとのおしゃべりでセマンティックモデルの定義からダッシュボード作成まで完成させる
nic_sugiyama
0
110
Claude Code の Sandbox 機能を Anthropic Sandbox Runtime(srt) で試そう!/lets-play-anthropic-sandbox-runtime
tomoki10
1
610
Socrates × Looker 〜セマンティックレイヤーで進化するデータ分析エージェント〜
hanon52_
3
2.4k
作って終わりにしない タイミーのセマンティックレイヤー育成の現在地
chanyou0311
4
2.4k
エラーバジェットのアラートのタイミングを考える.pdf
kairim0
0
150
小さくはじめるSLI/SLO ~育てながら組織に定着させる実践知~ / Starting Small with SLI/SLOs: Building Adoption Through Continuous Growth
nari_ex
7
1.9k
入門!AWS Blocks
ysuzuki
1
130
Snowflakeと仲良くなる第一歩
coco_se
4
480
プロダクト開発から業務改善コンサルまで。事業全体へ「染み出す」ことで広がるエンジニアの可能性
ham0215
0
130
200個のGitHubリポジトリを横断調査したかった
icck
0
130
Featured
See All Featured
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
370
WCS-LA-2024
lcolladotor
0
630
Java REST API Framework Comparison - PWX 2021
mraible
34
9.4k
What does AI have to do with Human Rights?
axbom
PRO
1
2.2k
For a Future-Friendly Web
brad_frost
183
10k
Designing for Timeless Needs
cassininazir
1
250
Paper Plane (Part 1)
katiecoart
PRO
0
9k
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
480
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
540
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.7k
Scaling GitHub
holman
464
140k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.3k
Transcript
SwiftUI Layout Apurin Mikhail @ YUMEMI.swift #15 ʙWWDC෮शձʙ
ࣗݾհ Apurin Mikhail ΞϓϦϯɾϛϋΠϧ auramagi - ΏΊΈͷiOSΤϯδχΞ - WWDC։࠵͔Βͣͬͱனٯసੜ׆Λͱʹͤͳ͍ -
ͳΜͰͦΜͳʹॵ͍ͷʁʁ auramagi
SwiftUIͷϨΠΞτॲཧͷ͓͞Β͍ 1. View͕ࢠViewʹαΠζΛఏҊ͢Δ 2. ࢠViewࣗͷαΠζΛܾΊΔ 3. View͕ࢠViewΛஔ͢Δ 4. ϐΫηϧάϦουʹ߹ΘͤΔͨΊ࠲ඪ͕ ࢛ࣺޒೖ͞ΕΔ
WWDC 2019 — Building Custom Views with SwiftUI
Color.mint .frame( minWidth: 100, maxWidth: 200, minHeight: 100, maxHeight: 200
) .frame(width: 300, height: 300) .border(.mint) SwiftUIͷϨΠΞτॲཧ 📱 W: 390 H: 763 .frame(minWidth: 200, …) .frame(width: 300, height: 300) Color ఏҊαΠζ ࣮αΠζ W: 300 H: 300 W: 200 H: 200 W: 300 H: 300 W: 200 H: 200 W: 200 H: 200
iOS 16·Ͱ ͜ͷϓϩηεʹϑοΫ͢Δ͜ͱ͕Ͱ͖ͳ͔ͬͨ - αΠζ.frameΛͬͯࢦఆ͢Δ - ViewͷαΠζ͔Βܭࢉ͍ͨ͠߹ɺ GeometryReaderΛ͏ - Viewʹࢠ
View ΛΒ͍ͤͨ߹ɺ GeometryReader + PreferenceΛ͏
ShapeͷαΠζܭࢉ 🆕 protocol Shape { func sizeThatFits(_ proposal: ProposedViewSize) ->
CGSize } struct ProposedViewSize : Equatable { public var width: CGFloat? public var height: CGFloat? } ఏҊαΠζ͔ΒࣗͷαΠζΛܭࢉ͢Δ - ෯ɾߴ͞ͷఏҊαΠζ - nilͷ߹ɺ ViewࣗͷidealαΠζΛͱΔ - . fi xedSize͕ࢦఆ͞Εͨͱ͖ʹnilʹͳΔ
ShapeͷαΠζܭࢉ 🆕 CoreText + SwiftUI DEMO https://gist.github.com/auramagi/ 82a05d81146507180ed1f9111bc2e37a
UIViewRepresentable / UIViewControllerRepresentableͷαΠζܭࢉ 🆕 protocol UIViewControllerRepresentable { func sizeThatFits( _
proposal: ProposedViewSize, uiViewController: UIViewControllerType, context: Context ) -> CGSize? } protocol UIViewRepresentable { func sizeThatFits( _ proposal: ProposedViewSize, uiView: UIViewType, context: Context ) -> CGSize? } ಉ͘͡ɺఏҊαΠζ͔ΒࣗͷαΠζΛܭࢉ͢Δ - UIViewͷsizeThatFits(_:)Λͬͯ൚༻తͳαΠζܭࢉΛ࣮Ͱ͖Δ - ܕใ͕͋Δ͔Βɺ͜ͷUIView (UIViewController)ʹಛԽͨ͠ܭࢉ࣮Ͱ͖Δ
Layoutϓϩτίϧ 🆕 protocol Layout { func sizeThatFits( proposal: ProposedViewSize, subviews:
Self.Subviews, cache: inout Self.Cache ) -> CGSize func placeSubviews( in bounds: CGRect, proposal: ProposedViewSize, subviews: Self.Subviews, cache: inout Self.Cache ) } - 2ͭͷඞਢͷϝιου - ࣗͷαΠζΛܾΊΔ - ࢠViewΛஔ͢Δ
Layoutϓϩτίϧ 🆕 Waterfall Layout DEMO https://gist.github.com/auramagi/ c4eb6f952d3432b71fc04c029567697a
Layoutϓϩτίϧ 🆕 🥰 خ͍͠ϙΠϯτ - αΠζͷΩϟογϡػߏ͕࣮Մೳ - SubviewͰҙͷΛLayoutValueKeyͰࢦఆ͢ΕLayoutͰड͚औΔ͜ͱ͕Ͱ͖Δ - HStack
/ VStack͕Layoutϓϩτίϧʹ४ڌ - Ξχϝʔγϣϯ͖ͰϨΠΞτΛಈతʹมߋͰ͖Δ 😔 ൵͍͠ϙΠϯτ - SubviewΛΞΫηεͰ͖ͳࣗ͘༝ʹมߋͰ͖ͳ͍ - LazyͷϨΠΞταϙʔτ͞Ε͍ͯͳ͍ͷͰॲཧίετʹҙ
ࢀߟ - Compose custom layouts with SwiftUI - https://developer.apple.com/videos/play/wwdc2022/10056/ -
Food Truck App (ެࣜαϯϓϧίʔυ) - https://github.com/apple/sample-food-truck - DiagonalDonutStackLayout - FlowLayout
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠