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
960
SwiftUIとUIKitを仲良くさせる
auramagi
3
6.2k
SwiftUIでUIViewを使うときのレイアウト処理 / Layout process when using UIKit view in SwiftUI
auramagi
0
770
Other Decks in Technology
See All in Technology
なぜ、あなたのAPIは使われないのか? AX時代の設計原則、ガードレール、運用体制
yokawasa
1
1.2k
データと地図で読む 大井町の「かわるもの、かわらないもの」
yoshiyama_hana
0
900
AIがAPIを書く時代に、私たちは何を設計すべきか
nagix
0
200
NYC Summit 2026 におけるAmazon Bedrock AgentCore のアップデート
ren8k
3
300
データエンジニアこそ組織のオントロジーに向き合うべき — 問いに答えるAIから、事業を動かすAIへ
gappy50
7
3k
reFACToring
moznion
1
1.1k
Claude Code並行開発環境の ムダ‧ムラ‧ムリを見直した話
muranakaaa
1
390
クラウドセキュリティ入門 ~安全なクラウド利用のための基礎知識~
lhazy
7
5.9k
検索技術知識0のエンジニアが広告検索システムを内製化して運用するまで
lycorptech_jp
PRO
0
180
システム監視入門
grimoh
5
790
20260724 情シスAI #1 「全従業員をAIネイティブにする」ために情シスがやっていること(公開版)
frtckty
0
160
【CEDEC2026】ゲームシナリオライターを支援するAIツール開発の実践 ― 設計とプロンプトの工夫 ―
cygames
PRO
1
170
Featured
See All Featured
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
470
WCS-LA-2024
lcolladotor
0
780
エンジニアに許された特別な時間の終わり
watany
108
250k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
2
3.7k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
1
380
How to Think Like a Performance Engineer
csswizardry
28
2.7k
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
760
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
410
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
200
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.2k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.8k
Marketing to machines
jonoalderson
1
5.6k
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
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠