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
【令和最新版】AWS Direct Connectと愉快なGWたちのおさらい
minorun365
PRO
5
750
隣接領域をBeyondするFinatextのエンジニア組織設計 / beyond-engineering-areas
stajima
1
270
初心者向けAWS Securityの勉強会mini Security-JAWSを9ヶ月ぐらい実施してきての近況
cmusudakeisuke
0
120
マルチプロダクトな開発組織で 「開発生産性」に向き合うために試みたこと / Improving Multi-Product Dev Productivity
sugamasao
1
300
Exadata Database Service on Dedicated Infrastructure(ExaDB-D) UI スクリーン・キャプチャ集
oracle4engineer
PRO
2
3.2k
第1回 国土交通省 データコンペ参加者向け勉強会③- Snowflake x estie編 -
estie
0
130
障害対応指揮の意思決定と情報共有における価値観 / Waroom Meetup #2
arthur1
5
470
個人でもIAM Identity Centerを使おう!(アクセス管理編)
ryder472
3
200
[CV勉強会@関東 ECCV2024 読み会] オンラインマッピング x トラッキング MapTracker: Tracking with Strided Memory Fusion for Consistent Vector HD Mapping (Chen+, ECCV24)
abemii
0
220
AWS Lambdaと歩んだ“サーバーレス”と今後 #lambda_10years
yoshidashingo
1
170
Amazon CloudWatch Network Monitor のススメ
yuki_ink
1
200
EventHub Startup CTO of the year 2024 ピッチ資料
eventhub
0
110
Featured
See All Featured
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
109
49k
Optimizing for Happiness
mojombo
376
70k
Typedesign – Prime Four
hannesfritz
40
2.4k
Designing for humans not robots
tammielis
250
25k
It's Worth the Effort
3n
183
27k
Designing Experiences People Love
moore
138
23k
Adopting Sorbet at Scale
ufuk
73
9.1k
Code Review Best Practice
trishagee
64
17k
Building Adaptive Systems
keathley
38
2.3k
Become a Pro
speakerdeck
PRO
25
5k
How to train your dragon (web standard)
notwaldorf
88
5.7k
We Have a Design System, Now What?
morganepeng
50
7.2k
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ߋ৽… ͷϧʔϓͰεΫϩʔϧ͕͓͔͘͠ͳΔ