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
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
SRE歴2ヶ月でも開発6年の知見を活かして、チームで止まっていた環境改善を前に進めた話
a_ono
1
210
Why is RC4 still being used?
tamaiyutaro
0
300
Claude Code 珍プレー好プレー
shinyasaita
0
280
生成AIの活用/high_school2026
okana2ki
0
110
ポストモーテム! DDoSからサイトは守れた。 でもビジネスは守れなかった。
bengo4com
0
1.4k
SRE Lounge Hiroshimaへの招待
grimoh
0
360
GuardrailからGovernanceへ~AIエージェント運用の次の課題~
sbspsy
1
220
そのタスクオンスケですか?
poropinai1966
0
140
はじめてのWDM
miyukichi_ospf
1
120
人を動かすのは時間ではなく、納得感 〜新任EMが入社3ヶ月、組織を2回変えた話〜
kakehashi
PRO
2
140
AIで政治は変わるのか? — 中高生と考えたAI時代の民主主義(東海高校サタデープログラム)
eitarosuda
0
400
金融の未来を考える / Thinking About the Future of Finance
ks91
PRO
0
180
Featured
See All Featured
The Mindset for Success: Future Career Progression
greggifford
PRO
0
410
The Illustrated Children's Guide to Kubernetes
chrisshort
51
52k
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
150
Building AI with AI
inesmontani
PRO
1
1.1k
The agentic SEO stack - context over prompts
schlessera
0
840
Visualization
eitanlees
152
17k
ラッコキーワード サービス紹介資料
rakko
1
3.8M
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
A Modern Web Designer's Workflow
chriscoyier
698
190k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.3k
Producing Creativity
orderedlist
PRO
348
40k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.5k
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
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠