Upgrade to Pro — share decks privately, control downloads, hide ads and more …

iPhoneX対応とScrollViewのcontentInset

 iPhoneX対応とScrollViewのcontentInset

ROPPONGI.swift #2 の発表用スライドです。

kNagadou

April 03, 2018
Tweet

More Decks by kNagadou

Other Decks in Programming

Transcript

  1.   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ͰࠔΔ࣌
  2. 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 ͷαΠζΛௐ੔ͨ͠Γ͠ͳ͍Α͏ʹ͢Δɻ
  3.   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 }
  4. ΋͠ɺ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 } }
  5. ʮ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 } }
  6.   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 } }