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

UIライブラリは どう設計されるべきか

kazuhiro4949
October 13, 2017

UIライブラリは どう設計されるべきか

iOSDC 2017 Reject Conference Days 1
https://iosdc-reject-conference.connpass.com/event/64175/

kazuhiro4949

October 13, 2017
Tweet

More Decks by kazuhiro4949

Other Decks in Technology

Transcript

  1. J04ΞϓϦͷ6*ϥΠϒϥϦ w ͜͜Ͱ͸ɺ6*,JUͷΫϥεΛܧ ঝͨ͠ܗͰఏڙ͞ΕΔɺ࠶ར༻ ՄೳͳΫϥεΛѻ͏ w $PSF"OJNBUJPO  $PSF(SBQIJDT $PSF5FYUͳͲ

    ͷ௿ϨΠϠϑϨʔϜϫʔΫ͸ ϑΥʔΧε͔Β֎͢ IUUQTEFWFMPQFSBQQMFDPNMJCSBSZDPOUFOUEPDVNFOUBUJPO$PDPB$PODFQUVBM$PSF"OJNBUJPO@HVJEF*OUSPEVDUJPO*OUSPEVDUJPOIUNM
  2. ͦͷϥΠϒϥϦͰ͸ɺUJUMF͕ઃఆ͞Εͨ7$Λ"SSBZͰ ౉͢ͱɺܾ·ͬͨσβΠϯͷϖʔδϯά6*͕࡞ΒΕΔ ˞Πϝʔδ ࣮ࡍʹؔΘͬͨϓϩμΫτͱ͸ҧ͍·͢ let ary: [UIViewController] = [ {

    $0.title = "Page1" return $0 }(UIViewController()), { $0.title = "Page2” return $0 }(UIViewController()), { $0.title = "Page3" return $0 }(UIViewController()) ] pagingViewController.childViewControllers = ary
  3. ͦͷϥΠϒϥϦͰ͸ɺUJUMF͕ઃఆ͞Εͨ7$Λ"SSBZͰ ౉͢ͱɺܾ·ͬͨσβΠϯͷϖʔδϯά6*͕࡞ΒΕΔ ˞Πϝʔδ ࣮ࡍʹؔΘͬͨϓϩμΫτͱ͸ҧ͍·͢ let ary: [UIViewController] = [ {

    $0.title = "Page1" return $0 }(UIViewController()), { $0.title = "Page2” return $0 }(UIViewController()), { $0.title = "Page3" return $0 }(UIViewController()) ] pagingViewController.childViewControllers = ary ϝχϡʔ͕͋Δ
  4. ͦͷϥΠϒϥϦͰ͸ɺUJUMF͕ઃఆ͞Εͨ7$Λ"SSBZͰ ౉͢ͱɺܾ·ͬͨσβΠϯͷϖʔδϯά6*͕࡞ΒΕΔ ˞Πϝʔδ ࣮ࡍʹؔΘͬͨϓϩμΫτͱ͸ҧ͍·͢ let ary: [UIViewController] = [ {

    $0.title = "Page1" return $0 }(UIViewController()), { $0.title = "Page2” return $0 }(UIViewController()), { $0.title = "Page3" return $0 }(UIViewController()) ] pagingViewController.childViewControllers = ary ϖʔδϯάՄೳͳ ίϯςϯπྖҬ͕͋Δ
  5. w 4FHVFͰઃఆͨ͠௨ৗͷ$IJME 7JFX$POUSPMMFSͱಉ͡Α͏ʹɺ ίʔυ্Ͱऔಘ͢Δ class ViewController: UIViewController { var menuViewController:

    PagingMenuViewController! var contentViewController: PagingContentViewController! // … // ... override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if let vc = segue.destination as? PagingMenuViewController { menuViewController = vc } else if let vc = segue.destination as? PagingContentViewController { contentViewController = vc } } } QSFQBSF GPSTFOEFS ͰTUPSZCPBSEͰઃఆ͠ ͨ7$ΛϓϩύςΟ΁ೖΕΔ
  6. var data: (menuTitle: String, vc: UIViewController) = [ (menuTitle: "test1",

    vc: UIViewController()), (menuTitle: "test2", vc: UIViewController()), (menuTitle: "test3", vc: UIViewController()) ] w ը໘ʹද͍ࣔͤͨ͞೚ҙͷσʔ λΛ༻ҙ͢Δ w ϝχϡʔ͸λΠτϧจࣈྻ ͷΈ w ίϯςϯπ͸ۭͷ7$Λ༻ҙ ͍ͯ͠Δ
  7. w ϝχϡʔͷදࣔΛ࣮૷͢Δ w ༻ҙͨ͠σʔλΛ%BUB4PVSDF ܦ༝ͰɺඞཁͳλΠϛϯάͰ౎ ౓ฦ͢ w 5BCMF7JFX΍$PMMFDUJPO7JFXͱ ಉ༷ͳ࢓૊ΈͰҎԼΛ౉͢ w

    σʔλ਺ w ηϧͷ෯ w σʔλΛόΠϯυͨ͠ηϧ // ϝχʔ෦෼ͷDataSource extension ViewController: PagingMenuViewControllerDataSource { func numberOfItemForMenuViewController( viewController: PagingMenuViewController) -> Int { return data.count } func menuViewController(viewController: PagingMenuViewController, widthForItemAt index: Int) -> CGFloat { return 100 } func menuViewController(viewController: PagingMenuViewController, cellForItemAt index: Int) -> PagingMenuViewCell { let cell = viewController.dequeueReusableCell(withReuseIdentifier: "MenuCell", for: index) as! MenuCell cell.titleLabel.text = data[index].menuTitle return cell } }
  8. w ίϯςϯπͷදࣔΛ࣮૷͢Δ w ༻ҙͨ͠σʔλΛ%BUB4PVSDF ܦ༝ͰɺඞཁͳλΠϛϯάͰ ౎౓ฦ͢ w 5BCMF7JFX΍$PMMFDUJPO7JFX ͱಉ༷ͳ࢓૊Έ w

    σʔλ਺ w σʔλΛόΠϯυͨ͠ 7JFX$POUSPMMFS // ίϯςϯπ෦෼ͷDataSource extension ViewController: PagingContentViewControllerDataSource { func numberOfItemForContentViewController( ɹ viewController: PagingContentViewController) -> Int { return data.count } func contentViewController(viewController: PagingContentViewController, viewControllerAt index: Int) -> UIViewController { return data[index].vc } }
  9. ࢀߟࢿྉ w 6*,JUc"QQMF%FWFMPQFS%PDVNFOUBUJPO w IUUQTEFWFMPQFSBQQMFDPNEPDVNFOUBUJPOVJLJU w $PODFQUTJO0CKFDUJWF$1SPHSBNNJOH w IUUQTEFWFMPQFSBQQMFDPNMJCSBSZDPOUFOUEPDVNFOUBUJPO(FOFSBM$PODFQUVBM $PDPB&ODZDMPQFEJB*OUSPEVDUJPO

    w LB[VIJSP1BHJOH,JU w IUUQTHJUIVCDPNLB[VIJSP1BHJOH,JU w ϝϧΧϦεϚϗͰ͔ΜͨΜϑϦϚΞϓϦ w IUUQTXXXNFSDBSJDPNKQ w :BIPPχϡʔεެࣜΞϓϦ:BIPPχϡʔε w IUUQTOFXTZBIPPDPKQQSPNPBQQZKOFXT w 4NBSU/FXT w IUUQTXXXTNBSUOFXTDPNKB