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 Lambda のトラブルシュートをしていて思うこと
kazzpapa3
2
180
B2B SaaSから見た最近のC#/.NETの進化
sansantech
PRO
0
880
iOS/Androidで同じUI体験をネ イティブで作成する際に気をつ けたい落とし穴
fumiyasac0921
1
110
AWS Lambdaと歩んだ“サーバーレス”と今後 #lambda_10years
yoshidashingo
1
180
Evangelismo técnico: ¿qué, cómo y por qué?
trishagee
0
360
なぜ今 AI Agent なのか _近藤憲児
kenjikondobai
4
1.4k
Amplify Gen2 Deep Dive / バックエンドの型をいかにしてフロントエンドへ伝えるか #TSKaigi #TSKaigiKansai #AWSAmplifyJP
tacck
PRO
0
390
これまでの計測・開発・デプロイ方法全部見せます! / Findy ISUCON 2024-11-14
tohutohu
3
370
ExaDB-D dbaascli で出来ること
oracle4engineer
PRO
0
3.9k
BLADE: An Attempt to Automate Penetration Testing Using Autonomous AI Agents
bbrbbq
0
320
Why App Signing Matters for Your Android Apps - Android Bangkok Conference 2024
akexorcist
0
130
Lexical Analysis
shigashiyama
1
150
Featured
See All Featured
Building Applications with DynamoDB
mza
90
6.1k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
27
840
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
329
21k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
Building Your Own Lightsaber
phodgson
103
6.1k
Code Review Best Practice
trishagee
64
17k
What's new in Ruby 2.0
geeforr
343
31k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.3k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
Into the Great Unknown - MozCon
thekraken
32
1.5k
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ߋ৽… ͷϧʔϓͰεΫϩʔϧ͕͓͔͘͠ͳΔ