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
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.2k
SwiftUIでUIViewを使うときのレイアウト処理 / Layout process when using UIKit view in SwiftUI
auramagi
0
760
Other Decks in Technology
See All in Technology
最近評価が難しくなった
maroon8021
0
250
地域 SRE コミュニティ最前線 / SRE NEXT 2026 Discussion Night Track C
muziyoshiz
0
150
脱金融のフューチャー・デザイン / Future Design Beyond Finance
ks91
PRO
0
140
なぜ私たちのSREプラクティスはなかなか機能しないのか 〜システムより先に組織を見る〜 / Why our SRE practices aren't really working
vtryo
1
2.4k
“全部コピーしない”ファイルデータの活用 : — FSx for ONTAP × S3 Tables × Icebergで作るメタデータカタログ
yoshiki0705
0
550
アカウントが増えてからでは遅い? ~ マルチアカウント統制の勘所 ~
kenichinakamura
0
190
product engineering with qa
nealle
0
150
美しいコードを書くためにF#を学んでみた話
yud0uhu
1
320
Control Planeで育てるBtoB SaaSの認証基盤 - SRE NEXT 2026
pokohide
1
1.5k
LiDAR SLAMの実装とセンサ融合 ~Lie群からContinuous-Time LIOまで~
naokiakai
1
1k
AWS Blocks を触ってみた/first-tach-aws-blocks
fossamagna
2
150
ループエンジニアリングでE2Eテストを実践
noriyukitakei
0
310
Featured
See All Featured
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Discover your Explorer Soul
emna__ayadi
2
1.2k
Mind Mapping
helmedeiros
PRO
1
280
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
1.1k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.8k
From π to Pie charts
rasagy
0
230
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
340
Unsuck your backbone
ammeep
672
58k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.9k
Building Applications with DynamoDB
mza
96
7.1k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
880
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
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠