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
サイバーセキュリティ概論 / Introduction to Cybersecurity
ks91
PRO
0
170
AI-DLCを活用した高品質・安全なAI駆動開発実践 / AI Driven Development with AI-DLC
yoshidashingo
0
160
新規事業を牽引する技術選定 〜フルスタックTypeScript開発の実践事例〜
nullnull
3
380
GoとSIMDとWasmの今。
askua
3
520
protovalidate-es を導入してみた
bengo4com
0
160
Socrates × Looker 〜セマンティックレイヤーで進化するデータ分析エージェント〜
hanon52_
3
1.8k
AIの性能が向上しても未解決な組織の重大問題は何か?/An Unsolved Organizational Problem in the Age of AI
moriyuya
3
530
Agentic Web
dynamis
1
200
関西に縁あるMicrosoft MVPsが語るCopilotの未来
kasada
0
1.2k
Agentic ERPをどう設計するか ー 受発注エージェントを動かす、現場の知見と設計思想ー
recerqainc
1
2k
チームで進めるAI駆動アジャイル×ウォーターフォール
kumaiu
0
120
AGENTS.mdとSkillsで始めるAIエージェント活用
sonoda_mj
2
150
Featured
See All Featured
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.9k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
We Are The Robots
honzajavorek
0
240
Utilizing Notion as your number one productivity tool
mfonobong
4
320
Unsuck your backbone
ammeep
672
58k
Code Review Best Practice
trishagee
74
20k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
210
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.6k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9.1k
A Soul's Torment
seathinner
6
2.9k
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
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠