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

制約のなかでContainerViewControllerを
つくる方法

 制約のなかでContainerViewControllerを
つくる方法

ChildViewControllerが依存しあっているような制約のもとでも、汎用のContainerViewControllerを作る方法を詳解します

Mitsuyoshi Yamazaki

September 18, 2018
Tweet

More Decks by Mitsuyoshi Yamazaki

Other Decks in Technology

Transcript

  1. ΠϯλʔϑΣʔεΛఆٛ͢Δ class ScrollableViewController: UIViewController { var scrollView: UIScrollView } class

    ContainerViewController: UIViewController { var headerViewController: UIViewController // ϔομʔ var viewControllers: [ScrollableViewController] // εΫϩʔϧίϯςϯπ } εΫϩʔϧίϯςϯπ͸ScrollViewΛ΋͍ͬͯΔඞཁ͕͋Δ
  2. class ScrollableViewController: UIViewController { var scrollView: UIScrollView } class ContainerViewController:

    UIViewController { var headerViewController: UIViewController // ϔομʔ var viewControllers: [ScrollableViewController] // εΫϩʔϧίϯςϯπ } ChildViewControllerͷ
 ಠཱੑΛ୲อ͢Δ ѻ͑ΔChildViewControllerʹ੍ݶ͕͔͔͍ͬͯΔ
  3. protocol Scrollable { var scrollView: UIScrollView! { get } }

    class ContainerViewController: UIViewController { var headerViewController: UIViewController // ϔομʔ var viewControllers: [UIViewController & Scrollable] // εΫϩʔϧίϯςϯπ } ChildViewControllerͷ
 ಠཱੑΛ୲อ͢Δ ඞਢͷ੍໿͸protocolʹ੾Γग़͢
  4. 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ͷมԽΛऔಘ͠ɺϔομʔߴ͞Λߋ৽