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
生成AIのガバナンスの全体像と現実解
fnifni
1
180
Wvlet: A New Flow-Style Query Language For Functional Data Modeling and Interactive Data Analysis - Trino Summit 2024
xerial
1
110
社内イベント管理システムを1週間でAKSからACAに移行した話し
shingo_kawahara
0
180
継続的にアウトカムを生み出し ビジネスにつなげる、 戦略と運営に対するタイミーのQUEST(探求)
zigorou
0
530
ブラックフライデーで購入したPixel9で、Gemini Nanoを動かしてみた
marchin1989
1
520
Snykで始めるセキュリティ担当者とSREと開発者が楽になる脆弱性対応 / Getting started with Snyk Vulnerability Response
yamaguchitk333
2
180
非機能品質を作り込むための実践アーキテクチャ
knih
3
1.1k
PHPからGoへのマイグレーション for DMMアフィリエイト
yabakokobayashi
1
170
祝!Iceberg祭開幕!re:Invent 2024データレイク関連アップデート10分総ざらい
kniino
2
260
2024年にチャレンジしたことを振り返るぞ
mitchan
0
130
開発生産性向上! 育成を「改善」と捉えるエンジニア育成戦略
shoota
2
320
バクラクのドキュメント解析技術と実データにおける課題 / layerx-ccc-winter-2024
shimacos
2
1.1k
Featured
See All Featured
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
510
The Pragmatic Product Professional
lauravandoore
32
6.3k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.1k
For a Future-Friendly Web
brad_frost
175
9.4k
Code Review Best Practice
trishagee
65
17k
The Cost Of JavaScript in 2023
addyosmani
45
7k
Designing for humans not robots
tammielis
250
25k
Writing Fast Ruby
sferik
628
61k
Designing on Purpose - Digital PM Summit 2013
jponch
116
7k
How to Think Like a Performance Engineer
csswizardry
22
1.2k
A better future with KSS
kneath
238
17k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.9k
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ߋ৽… ͷϧʔϓͰεΫϩʔϧ͕͓͔͘͠ͳΔ