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
iPhoneX対応とScrollViewのcontentInset
Search
kNagadou
April 03, 2018
Programming
1
670
iPhoneX対応とScrollViewのcontentInset
ROPPONGI.swift #2 の発表用スライドです。
kNagadou
April 03, 2018
Tweet
Share
More Decks by kNagadou
See All by kNagadou
勇気を出して、Appleにバグレポートを出してみませんか?
knagadou
0
1.1k
Musicアプリのトランジションを再現する
knagadou
3
2.4k
テスト実行時に 不要な初期化コードを実行しないようにする
knagadou
4
1.4k
Other Decks in Programming
See All in Programming
광고 소재 심사 과정에 AI를 도입하여 광고 서비스 생산성 향상시키기
kakao
PRO
0
170
現場で役立つモデリング 超入門
masuda220
PRO
15
3.1k
讓數據說話:用 Python、Prometheus 和 Grafana 講故事
eddie
0
390
みんなでプロポーザルを書いてみた
yuriko1211
0
230
よくできたテンプレート言語として TypeScript + JSX を利用する試み / Using TypeScript + JSX outside of Web Frontend #TSKaigiKansai
izumin5210
3
950
どうして僕の作ったクラスが手続き型と言われなきゃいけないんですか
akikogoto
1
100
subpath importsで始めるモック生活
10tera
0
110
イベント駆動で成長して委員会
happymana
1
300
ピラミッド、アイスクリームコーン、SMURF: 自動テストの最適バランスを求めて / Pyramid Ice-Cream-Cone and SMURF
twada
PRO
10
1.2k
ふかぼれ!CSSセレクターモジュール / Fukabore! CSS Selectors Module
petamoriken
0
150
『ドメイン駆動設計をはじめよう』のモデリングアプローチ
masuda220
PRO
8
520
Better Code Design in PHP
afilina
PRO
0
120
Featured
See All Featured
Designing the Hi-DPI Web
ddemaree
280
34k
A better future with KSS
kneath
238
17k
VelocityConf: Rendering Performance Case Studies
addyosmani
325
24k
Gamification - CAS2011
davidbonilla
80
5k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
93
16k
Automating Front-end Workflow
addyosmani
1366
200k
Intergalactic Javascript Robots from Outer Space
tanoku
269
27k
Producing Creativity
orderedlist
PRO
341
39k
Music & Morning Musume
bryan
46
6.2k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
506
140k
Transcript
J1IPOF9ରԠͱ 6*4DSPMM7JFXͷDPOUFOU*OTFU ,":"$ٕज़෦ ,B[VNBTB/"("%0 30110/(*TXJGU
w ,B[VNBTB/"("%0 w ,":"$d w 5XJUUFS!L[NTOHE w ʢʣ/1$+ϑΟδʔΫϊʔϏε DNҎԼΫϥεग़༧ఆ w
IUUQTOQDKKQDPOUFTUOFXHFOFSBUJPODMBTTJD 1SPpMF
2ݮྔதʹ৯ͯྑ͍ͷʁ ͓ण࢘ ύελྉཧ ͓ʹ͗Γ εΠʔπ ࠓ͔Βग़དྷΔݮྔΫΠζ
"શ෦0, ʢ˞ઁऔ͢ΔλΠϛϯάɺຊؾʹΑΔʣ ࠓ͔Βग़དྷΔݮྔΫΠζ
2ͲͷτϨʔχϯά͕ےΛେ͖͘Ͱ͖Δʁ ϕϯνϓϨεLHYճ ϕϯνϓϨεLHYճ ࠓ͔Βग़དྷΔےංେΫΠζ
"ͲͪΒےංେ͢Δ ʢ˞ݶք·Ͱ͍ࠐΉ͜ͱ͕લఏʣ ࠓ͔Βग़དྷΔےංେΫΠζ
ϓϥίϨ8FEEJOH IUUQTQMBDPMFXFEEJOH %SFTTZCZϓϥίϨ IUUQTESFTTZQMBDPMFXFEEJOH ϓϥίϨ
ˎ8FC൛ IUUQTXFCMPCJDP ˎJ5VOFT"QQ4UPSF IUUQTJUVOFTBQQMFDPNKQBQQMPCJϩϏʔJE NU ˎ"OESPJE IUUQTQMBZHPPHMFDPNTUPSFBQQTEFUBJMT JEDPNLBZBDOBLBNBQIMKB
ήʔϜ߈ུνϟοτ4/4 -PCJ
6QEBUFGPSJ1IPOF9
#VJMEXJUIJ044%, 9DPEFY
J1IPOF9ͷσΟεϓϨΠରԠ 4BGF"SFBରԠ ˠ6*4DSPMM7JFXͷදࣔྖҬ͕͓͔͍͠ɻௐ্͕ख͘Ͱ͖ͳ͍ɻ 6*4DSPMM7JFXͷ"VUP-BZPVUͱDPOUFOU*OTFUʹ͍͓ͭͯ͞Β͍ͯ͠ΈΔɻ
6*4DSPMM7JFX 6*5BCMF7JFX ͷ"VUP-BZPVUͰࠔΔ࣌ 6*/BWJHBUJPO#BS 6*4FBSDI#BS 6*5BCMF7JFX
DPOUFOU*OTFUͱ 6*4DSPMM7JFXͷGSBNF DPOUFOU*OTFUUPQ
DPOUFOU*OTFUͱ 6*4DSPMM7JFXͷGSBNF DPOUFOU*OTFUUPQ 6*4DSPMM7JFXίϯςϯπपลʹ ઃఆͰ͖Δ༨നͷ͜ͱ
6*4DSPMM7JFX 6*5BCMF7JFX ͷ"VUP-BZPVUͰࠔΔ࣌
6*4DSPMM7JFX 6*5BCMF7JFX ͷ"VUP-BZPVUͰࠔΔ࣌ Ṗͷεϖʔε
6*4DSPMM7JFX 6*5BCMF7JFX ͷ"VUP-BZPVUͰࠔΔ࣌ ͜͜ಉ͡Α͏ʹݟ͑Δ͕ɺ 6*5BCMF7JFX͕ը໘͍ͬͺ͍ʹ දࣔ͞Ε͍ͯͳ͍͜ͱ͕͔Δ
6*4DSPMM7JFX 6*5BCMF7JFX ͷ"VUP-BZPVUͰࠔΔ࣌ 6*4FBSDI#BSͷΈ্ʹҠಈ ͯ͠͠·͍ɺṖͷεϖʔε͕ൃੜ
DPOTUBOU 6*/BWJHBUJPO#BS 6*4FBSDI#BSͷߴ͞ Ͱ 6*5BCMF7JFXͷUPQʹ੍Λ͔͚͍ͯΔɻ ˠ6*4FBSDI#BSͱ6*5BCMF7JFXͷίϯςϯπͷؒʹ
ෆࣗવͳ伱͕ؒੜ·Εͯ͠·͏ɻ ˠ6*4FBSDI#BSͷڍಈɺ6*5BCMF7JFX͕ ը໘͍ͬͺ͍ʹදࣔ͞Ε͍ͯΔ͜ͱΛظ͍ͯ͠Δɻ 6*4DSPMM7JFX 6*5BCMF7JFX ͷ"VUP-BZPVUͰࠔΔ࣌
Ξϯνύλʔϯ ɾϔομʔʢϑολʔʣͳͲͷߴ͞ʹ߹Θͤͯɺ6*4DSPMM7JFXʹ"VUP -BZPVUΛ͔͚ͯ͠·͏ɻ ɾ$IJME7JFX$POUSPMMFS͔Β1BSFOU7JFX$POUSPMMFSͷ7JFXϑϨʔϜ Λࢀরͯ͠ɺ6*4DSPMM7JFXʹ"VUP-BZPVUΛ͔͚ͯ͠·͏ɻ
w ඪ४ͷ6* 6*4FBSDI#BSͳͲ Ճͨ࣌͠ʹɺෆࣗવͳ6*දࣔʹͳΔɻ w ϔομʔϑολʔͳͲʹ#MVSޮՌΛ͚͍ͨ࣌ʹࠔΔɻ w 1BSFOU7JFX$POUSPMMFSͱ$IJME7JFX$POUSPMMFSͷґଘੑ͕ߴ·Δʢϝϯ ςφϯε͠ਏ͍ʣɻ
ࠔΔ͜ͱ·ͱΊ
"QQMFͷΨΠυϥΠϯʹԊ͏Α͏ʹ 6*4DSPMM7JFXΛ࣮͢Δ IUUQTEFWFMPQFSBQQMFDPNKQEPDVNFOUBUJPO6*4DSPMM7JFX@QHQEG
6*4DSPMM7JFXը໘͍ͬͺ͍ʹදࣔ͢Δ self.tableView.translatesAutoresizingMaskIntoConstraints = false NSLayoutConstraint.activate([ self.tableView.topAnchor.constraint(equalTo: self.view.topAnchor), self.tableView.bottomAnchor.constraint(equalTo:
self.view.bottomAnchor), self.tableView.trailingAnchor.constraint(equalTo: self.view.trailingAnchor), self.tableView.leadingAnchor.constraint(equalTo: self.view.leadingAnchor) ]) ˠϔομʔϑολʔͷߴ͞ʹ߹Θͤͯ6*4DSPMM7JFX ͷαΠζΛௐͨ͠Γ͠ͳ͍Α͏ʹ͢Δɻ
σϑΥϧτͰBEKVTUFE$POUFOU*OTFU͕༗ޮʹͳ͍ͬͯΔͨΊɺಛʹ DPOUFOU*OTFUͷௐෆཁɻ ˠBEKVTUFE$POUFOU*OTFUʹΑΓɺDPOUFOU*OTFU͕4BGF"SFBʹ߹ Θͤͯࣗಈௐ͞ΕΔɻ DPOUFOU*OTFUͷௐ J04
DPOUFOU*OTFUͷௐ J04 1BSFOU7JFX$POUSPMMFSͰཧ͍ͯ͠Δ7JFXͷϑϨʔϜʢϔομʔϑο λʔͳͲʣΛ$IJME7JFX$POUSPMMFSʹ͍ͨ͠߹ɻ ˠBEEJUJPOBM4BGF"SFB*OTFUΛ͏ɻ ˠϔομʔʢϑολʔʣͷϑϨʔϜͷ༨നΛ $IJME7JFX$POUSPMMFSͰཧ͢Δ7JFXͷTBGF"SFB*OTFUTʹ͢͜ͱ ͕Ͱ͖Δɻ
@available(iOS 11.0, *) override func viewSafeAreaInsetsDidChange() { super.viewSafeAreaInsetsDidChange() let childVCAdditionalSafeAreaInsets = UIEdgeInsetsMake(self.childVCAdditionalSafeAreaInsetsTop, 0, 0, 0) self.childVC.additionalSafeAreaInsets = childVCAdditionalSafeAreaInsets }
͠ɺBEKVTUFE$POUFOU*OTFUΛΘͳ͍ TDSPMM7JFXDPOUFOU*OTFU"EKVTUNFOU#FIBWJPSOFWFS ͱ͢Δ߹ɻ ˠWJFX%JE-BZPVU4VCWJFXT ͰɺTDSPMM7JFXDPOUFOU*OTFUΛௐɻ DPOUFOU*OTFUͷௐ J04 override
func viewDidLayoutSubviews() { super.viewDidLayoutSubviews() if #available(iOS 11.0, *) { self.tableView.contentInset = UIEdgeInsetsMake(self.view.safeAreaInsets.top, 0, self.view.safeAreaInsets.bottom, 0) self.tableView.scrollIndicatorInsets = self.tableView.contentInset } }
ʮBEKVTUFE$POUFOU*OTFUΛΘͳ͍߹ʯͱ΄΅ಉ͡ɻ ˠWJFX%JE-BZPVU4VCWJFXT ͷλΠϛϯάͰUPQ-BZPVU(VJEF CPUUPN-BZPVU(VJEFͷͱɺૠೖ͍ͨ͠JOTFUΛͯ͠ TDSPMM7JFXDPOUFOU*OTFUΛௐɻ ˠૠೖ͍ͨ͠JOTFUɺ7JFX$POUSPMMFSͷੜ࣌ʹ͢ɻ DPOUFOU*OTFUͷௐ
J04Ҏલ override func viewDidLayoutSubviews() { super.viewDidLayoutSubviews() if #available(iOS 11.0, *) { } else { self.topLayoutMarginConstraint.constant = 0 self.tableView.contentInset = UIEdgeInsetsMake(self.topLayoutGuide.length, 0, self.bottomLayoutGuide.length, 0) self.tableView.scrollIndicatorInsets = self.tableView.contentInset } }
DPOUFOU*OTFUͷௐ J04Ҏલ // ChildViewController @available(iOS, deprecated: 11.0, message:
"iOS11.0Ҏ߱ additionalSafeAreaInsets Ͱௐ͢Δɻ") private var additionalScrollViewContentInsetTop: CGFloat = 0.0 init(additionalScrollViewContentInsetTop: CGFloat) { self.additionalScrollViewContentInsetTop = additionalScrollViewContentInsetTop super.init(nibName: nil, bundle: nil) } ~~~ override func viewDidLayoutSubviews() { super.viewDidLayoutSubviews() if #available(iOS 11.0, *) { // do nothing } else { let contentInset = UIEdgeInsetsMake(self.topLayoutGuide.length + self.additionalScrollViewContentInsetTop, 0, self.bottomLayoutGuide.length, 0) self.scrollView.contentInset = contentInset self.scrollView.scrollIndicatorInsets = self.scrollView.contentInset } }
ࢀߟ <>4VCNJUUJOHJ04BQQTUPUIF"QQ4UPSF IUUQTEFWFMPQFSBQQMFDPNJPTTVCNJU <>6*4DSPMM7JFXBEKVTUFE$POUFOU*OTFU IUUQTEFWFMPQFSBQQMFDPNEPDVNFOUBUJPOVJLJUVJTDSPMMWJFX BEKVTUFEDPOUFOUJOTFU MBOHVBHFPCKD <>6*4DSPMM7JFXDPOUFOU*OTFU"EKVTUNFOU#FIBWJPS IUUQTEFWFMPQFSBQQMFDPNEPDVNFOUBUJPOVJLJUVJTDSPMMWJFX DPOUFOUJOTFUBEKVTUNFOUCFIBWJPS
MBOHVBHFPCKD <>J046*4DSPMM7JFXϓϩάϥϛϯάΨΠυ IUUQTEFWFMPQFSBQQMFDPNKQEPDVNFOUBUJPO6*4DSPMM7JFX@QHQEG
͋Γ͕ͱ͏͍͟͝·ͨ͠