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
制約のなかでContainerViewControllerを つくる方法
Search
Mitsuyoshi Yamazaki
September 18, 2018
Technology
5
800
制約のなかでContainerViewControllerを つくる方法
ChildViewControllerが依存しあっているような制約のもとでも、汎用のContainerViewControllerを作る方法を詳解します
Mitsuyoshi Yamazaki
September 18, 2018
Tweet
Share
More Decks by Mitsuyoshi Yamazaki
See All by Mitsuyoshi Yamazaki
人工生命
mitsuyoshiyamazaki
0
1.4k
人工生命の世界
mitsuyoshiyamazaki
0
1.7k
Other Decks in Technology
See All in Technology
フロントエンド設計にモブ設計を導入してみた / 20241212_cloudsign_TechFrontMeetup
bengo4com
0
1.9k
TSKaigi 2024 の登壇から広がったコミュニティ活動について
tsukuha
0
160
PHP ユーザのための OpenTelemetry 入門 / phpcon2024-opentelemetry
shin1x1
1
220
LINE Developersプロダクト(LIFF/LINE Login)におけるフロントエンド開発
lycorptech_jp
PRO
0
120
Qiita埋め込み用スライド
naoki_0531
0
5.1k
どちらを使う?GitHub or Azure DevOps Ver. 24H2
kkamegawa
0
800
複雑性の高いオブジェクト編集に向き合う: プラガブルなReactフォーム設計
righttouch
PRO
0
110
DevOps視点でAWS re:invent2024の新サービス・アプデを振り返ってみた
oshanqq
0
180
非機能品質を作り込むための実践アーキテクチャ
knih
5
1.4k
新機能VPCリソースエンドポイント機能検証から得られた考察
duelist2020jp
0
220
継続的にアウトカムを生み出し ビジネスにつなげる、 戦略と運営に対するタイミーのQUEST(探求)
zigorou
0
560
Microsoft Azure全冠になってみた ~アレを使い倒した者が試験を制す!?~/Obtained all Microsoft Azure certifications Those who use "that" to the full will win the exam! ?
yuj1osm
2
110
Featured
See All Featured
How to Think Like a Performance Engineer
csswizardry
22
1.2k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
810
Building Applications with DynamoDB
mza
91
6.1k
Building Adaptive Systems
keathley
38
2.3k
Code Review Best Practice
trishagee
65
17k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.5k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
95
17k
A designer walks into a library…
pauljervisheath
204
24k
Practical Orchestrator
shlominoach
186
10k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
We Have a Design System, Now What?
morganepeng
51
7.3k
Transcript
੍ͷͳ͔Ͱ ContainerViewControllerΛ ͭ͘Δํ๏ @vespid v2.2.1
About me • Twitter: @vespid • GitHub: mitsuyoshi-yamazaki • SpeeeͰSwift։ൃ৽نࣄۀͷ
ϢʔβʔΠϯλϏϡʔͳͲ
ࡢॴଐ͍ͯͨ͠ࣄۀ෦ • iOS։ൃऀͱͯ͠ ඒ༰ΞϓϦΛ୲ • TwitterͷϓϩϑΟʔϧ ը໘ͷ࠶ݱ
͍͍ײ͡ʹOSSԽͰ͖ͨ HJUIVCDPNTQFFF 4DSPMMBCMF5BC$POUSPMMFS
Έͳ͞Μ
ᕒͷUI͕࠶ར༻Ͱ͖ͳ͍
ͱ͍͏͜ͱͳ͍Ͱ͠ΐ͏͔
ContainerViewControllerΛ ͬͨ͜ͱͷ͋Δํ ଟ͍ͱࢥ͍·͕͢
൚༻Խ͕͍͜͠ͱ
੍ͷͳ͔Ͱ ContainerViewControllerΛ ͭ͘Δํ๏ʹ͍ͭͯઆ໌͠·͢
• εΫϩʔϧʹΑͬͯ ϔομʔ͕ॖΉ • ChildVC ϔομʔͱλϒͷத ྫɿTwitter UI
Twitter UIͷ;ͨͭͷཁૉ 1.ScrollViewΛΈ߹ΘͤͨView • εΫϩʔϧͱಉظͨ͠Ξχϝʔγϣϯ 2.൚༻ContainerViewController • ChildViewControllerಉ࢜ͷಠཱΛอͭ Twitter UIΛςʔϚʹબΜͩཧ༝ɿ
Twitter UIͷ;ͨͭͷཁૉ 1.ScrollViewΛΈ߹ΘͤͨView • εΫϩʔϧͱಉظͨ͠Ξχϝʔγϣϯ 2.൚༻ContainerViewController • ChildViewControllerಉ࢜ͷಠཱΛอͭ Twitter UIΛςʔϚʹબΜͩཧ༝ɿ
੍ͷͱ൚༻Խ͢Δͷ͕͍͠
Ͳ͏ͭ͘Δ͔ʁ
ContainerViewControllerͷઃܭ • ΠϯλʔϑΣʔεΛఆٛ͢Δ • ChildViewControllerؒͷಠཱੑΛ୲อ͢Δ • ্࣮ͷ੍Λղܾ͢ΔɿࠓճScrollViewؔ࿈
ContainerViewControllerͷઃܭ • ΠϯλʔϑΣʔεΛఆٛ͢Δ • ChildViewControllerؒͷಠཱੑΛ୲อ͢Δ • ্࣮ͷ੍Λղܾ͢ΔɿࠓճScrollViewؔ࿈
ΠϯλʔϑΣʔεΛఆٛ͢Δ • ཁ • ͍͍͢ΠϯλʔϑΣʔεΛ༻ҙ͍ͨ͠ • UIKit४ڌ
ΠϯλʔϑΣʔεΛఆٛ͢Δ ϔομʔ λϒ εΫϩʔϧίϯςϯπ
ΠϯλʔϑΣʔεΛఆٛ͢Δ class ScrollableViewController: UIViewController { var scrollView: UIScrollView } class
ContainerViewController: UIViewController { var headerViewController: UIViewController // ϔομʔ var viewControllers: [ScrollableViewController] // εΫϩʔϧίϯςϯπ } εΫϩʔϧίϯςϯπScrollViewΛ͍ͬͯΔඞཁ͕͋Δ
ContainerViewControllerͷઃܭ • ΠϯλʔϑΣʔεΛఆٛ͢Δ • ChildViewControllerؒͷಠཱੑΛ୲อ͢Δ • ্࣮ͷ੍Λղܾ͢ΔɿࠓճScrollViewؔ࿈
ChildViewControllerͷ ಠཱੑΛ୲อ͢Δ • ཁ • ҙͷChildViewControllerΛѻ͍͍ͨ
class ScrollableViewController: UIViewController { var scrollView: UIScrollView } class ContainerViewController:
UIViewController { var headerViewController: UIViewController // ϔομʔ var viewControllers: [ScrollableViewController] // εΫϩʔϧίϯςϯπ } ChildViewControllerͷ ಠཱੑΛ୲อ͢Δ ѻ͑ΔChildViewControllerʹ੍ݶ͕͔͔͍ͬͯΔ
protocol Scrollable { var scrollView: UIScrollView! { get } }
class ContainerViewController: UIViewController { var headerViewController: UIViewController // ϔομʔ var viewControllers: [UIViewController & Scrollable] // εΫϩʔϧίϯςϯπ } ChildViewControllerͷ ಠཱੑΛ୲อ͢Δ ඞਢͷ੍protocolʹΓग़͢
ContainerViewControllerͷઃܭ • ΠϯλʔϑΣʔεΛఆٛ͢Δ • ChildViewControllerؒͷಠཱੑΛ୲อ͢Δ • ্࣮ͷ੍Λղܾ͢ΔɿࠓճScrollViewؔ࿈
• λϒͷίϯςϯπΛ εΫϩʔϧͰ͖Δ • ্·ͰεΫϩʔϧ͢Δͱ ࿈ଓతʹϔομʔ͕ॖΉ ScrollViewཁ݅
࣮Ҋ 1. ScrollViewΛೖΕࢠʹ͢Δ 2. εΫϩʔϧͰScrollView.frameΛߋ৽͢Δ 3. ScrollView.contentInsetΛར༻͢Δ
࣮Ҋ 1. ScrollViewΛೖΕࢠʹ͢Δ 2. εΫϩʔϧͰScrollView.frameΛߋ৽͢Δ 3. ScrollView.contentInsetΛར༻͢Δ
ScrollView.contentInsetΛ ར༻͢Δ
None
࣮
ScrollView.contentInsetΛར༻͢Δ ࣮ tabContentViewController.scrollView.contentInset.top = headerViewController.maximumHeight tabContentViewController.scrollView.observe(\.contentOffset) { (_, change) in
guard let offset = change.newValue else { return } self.headerHeightConstraint.constant = -(self.tabViewHeight + offset.y) } ContentOffsetͷมԽΛऔಘ͠ɺϔομʔߴ͞Λߋ৽
contentOffsetΛऔಘ͢ΔͳΒ scrollViewDidScroll Λ͑Α͍ͷͰ
ScrollViewDelegateΛ ར༻͠ͳ͍ཧ༝ • σϦήʔτʹઃఆͰ͖ΔΠϯελϯε ͻͱͭͳͷͰɺίϯςφଆͰར༻͢Δͱ ChildViewControllerͷσϦήʔτϝιου͕ ݺΕͳ͘ͳΔͨΊ
·ͱΊ • ΠϯλʔϑΣʔεΛઌʹߟ͑Δ • ChildViewControllerؒͷಠཱΛอͭʹ protocolΛ͏ • ScrollViewಛੑΛཧղͯ͠͏ • ChildViewControllerͷdelegateΛԣऔΓ͠ͳ͍
!WFTQJE HJUIVCDPNTQFFF4DSPMMBCMF5BC$POUSPMMFS ੍ͷͳ͔Ͱ ContainerViewControllerΛ ͭ͘Δํ๏
None
None
ิࢿྉ
ScrollView࣮ Ҋ
1. ScrollViewΛೖΕࢠʹ͢Δ
1. ScrollViewΛೖΕࢠʹ͢Δ ϔομʔ λϒ εΫϩʔϧίϯςϯπ
1. ScrollViewΛೖΕࢠʹ͢Δ • ࿈ଓͯ͠εΫϩʔϧ Ͱ͖ͳ͍
1. ScrollViewΛೖΕࢠʹ͢Δ આ໌ɿ • ͻͱͭͷScrollView͕εϫΠϓδΣενϟʔΛ ड͚औΔͱɺͦͷεΫϩʔϧ͕ऴΘΔ·Ͱ ଞͷScrollViewʹδΣενϟʔ͕·ΘΒͳ͍ͨΊ
2. εΫϩʔϧͰScrollView.frameΛ ߋ৽͢Δ
2. εΫϩʔϧͰScrollView.frameΛߋ৽͢Δ ϔομʔ λϒ εΫϩʔϧίϯςϯπ
2. εΫϩʔϧͰScrollView.frameΛߋ৽͢Δ • ʮϔομʔ͕ॖΉʯͷ͕ཁ݅ • ͦΕʮϔομʔҎ֎͕͕Δʯͱಉ͡ • εΫϩʔϧʹΑͬͯScrollView.frame.heightΛ มߋ͢Ε࣮ݱͰ͖ΔͷͰͳ͍͔ʁ
2. εΫϩʔϧͰScrollView.frameΛߋ৽͢Δ આ໌ɿ • εΫϩʔϧதʹScrollView.frame͕ߋ৽͞ΕΔͱ ʮϢʔβʔ͕৮͍ͬͯΔ(contentOffset)ʯ͕ มΘͬͯ͠·͏ • frameߋ৽ˠcontentOffsetߋ৽ˠframeߋ৽… ͷϧʔϓͰεΫϩʔϧ͕͓͔͘͠ͳΔ