{"id":1382,"date":"2017-12-26T22:04:19","date_gmt":"2017-12-26T13:04:19","guid":{"rendered":"http:\/\/blue-bear.jp\/kb\/?p=1382"},"modified":"2018-01-01T11:46:50","modified_gmt":"2018-01-01T02:46:50","slug":"swift4-uipageviewcontroller%e3%81%a7%e3%83%8b%e3%83%a5%e3%83%bc%e3%82%b9%e3%82%a2%e3%83%97%e3%83%aa%e3%81%a3%e3%81%bd%e3%81%84%e3%83%9a%e3%83%bc%e3%82%b8%e3%83%b3%e3%82%b0%e6%a9%9f%e8%83%bd%e3%82%92","status":"publish","type":"post","link":"https:\/\/blue-bear.jp\/kb\/swift4-uipageviewcontroller%e3%81%a7%e3%83%8b%e3%83%a5%e3%83%bc%e3%82%b9%e3%82%a2%e3%83%97%e3%83%aa%e3%81%a3%e3%81%bd%e3%81%84%e3%83%9a%e3%83%bc%e3%82%b8%e3%83%b3%e3%82%b0%e6%a9%9f%e8%83%bd%e3%82%92\/","title":{"rendered":"[swift4] UIPageViewController\u3067\u30cb\u30e5\u30fc\u30b9\u30a2\u30d7\u30ea\u3063\u307d\u3044\u30da\u30fc\u30b8\u30f3\u30b0\u6a5f\u80fd\u3092\u5b9f\u88c5"},"content":{"rendered":"<p>\u74b0\u5883\uff1axcode9 , swift4<\/p>\n<p>\u30cb\u30e5\u30fc\u30b9\u30a2\u30d7\u30ea\u3063\u307d\u304f\u3001\u753b\u9762\u4e0a\u306b\u30da\u30fc\u30b8\u30f3\u30b0\u6a5f\u80fd\u3092\u5b9f\u88c5\u3057\u305f\u304f\u3001PagingMenuController\u3084\u3089\u3001XLPagerTabStrip\u3084\u3089\u3092\u5c0e\u5165\u3057\u3066\u307f\u305f\u3082\u306e\u306e\u3001pod\u30d5\u30a1\u30a4\u30eb\u304c\u306a\u305c\u304b\u8aad\u307f\u8fbc\u3081\u305a\u3001UIPageViewController\u3092\u4f7f\u7528\u3057\u3066swift\u30cd\u30a4\u30c6\u30a3\u30d6\u6a5f\u80fd\u3067\u5b9f\u88c5\u3002<\/p>\n<h2>ContainerView\u306bPageViewController\u3092Embed<\/h2>\n<p>Storyboard\u3067ViewController\u3092\u914d\u7f6e\u3001\u305d\u306e\u4e0a\u306bContainerView\u3092\u9069\u5207\u306a\u5927\u304d\u3055\u3067\u914d\u7f6e\u3002<\/p>\n<p>ContainerView\u3092\u914d\u7f6e\u3059\u308b\u3068\u81ea\u52d5\u7684\u306b\u3064\u3044\u3066\u304f\u308bEmbed\u3055\u308c\u3066\u304f\u308bView\u306f\u4e0d\u8981\u306a\u306e\u3067\u3001\u524a\u9664\u3002<\/p>\n<p>PageViewController\u3092\u914d\u7f6e\u3057\u3001ContainerView\u304b\u3089\u77e2\u5370\u3067Embed\u3002<\/p>\n<p>ViewController\u306b\u306f\u753b\u9762\u5207\u308a\u66ff\u3048\u306eUISegmentedControl\u3092\u4e0a\u90e8\u306b\u914d\u7f6e\u3002\uff08\u3042\u3068\u3067\u30b5\u30a4\u30ba\u3084\u8272\u3092\u5909\u3048\u308b\u3053\u3068\u304c\u3067\u304d\u308b\uff09<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-1385\" src=\"http:\/\/blue-bear.jp\/kb\/wp-content\/uploads\/2017\/12\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2017-12-26-21.41.28-1024x918.png\" alt=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2017-12-26 21.41.28\" width=\"1024\" height=\"918\" srcset=\"https:\/\/blue-bear.jp\/kb\/wp-content\/uploads\/2017\/12\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2017-12-26-21.41.28-1024x918.png 1024w, https:\/\/blue-bear.jp\/kb\/wp-content\/uploads\/2017\/12\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2017-12-26-21.41.28-300x269.png 300w, https:\/\/blue-bear.jp\/kb\/wp-content\/uploads\/2017\/12\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2017-12-26-21.41.28-768x688.png 768w, https:\/\/blue-bear.jp\/kb\/wp-content\/uploads\/2017\/12\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2017-12-26-21.41.28.png 1328w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/p>\n<h2>FirstViewController\u3068SecondViewController\u3092\u4f5c\u6210<\/h2>\n<p>StoryBoard\u306b\u305d\u308c\u305e\u308c\u306e\u30da\u30fc\u30b8\u5185\u5bb9\u3092\u8868\u793a\u3059\u308bFirstViewController\u3068SecondViewController\u3092\u914d\u7f6e\u3002<\/p>\n<p>\u305d\u308c\u305e\u308c\u306eViewController\u306eIdentity\u306eStoryBoard ID\u306b\u300cFirst\u300d\u300cSecond\u300d\u3068\u5165\u529b\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1386\" src=\"http:\/\/blue-bear.jp\/kb\/wp-content\/uploads\/2017\/12\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2017-12-26-22.01.43.png\" alt=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2017-12-26 22.01.43\" width=\"516\" height=\"408\" srcset=\"https:\/\/blue-bear.jp\/kb\/wp-content\/uploads\/2017\/12\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2017-12-26-22.01.43.png 516w, https:\/\/blue-bear.jp\/kb\/wp-content\/uploads\/2017\/12\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2017-12-26-22.01.43-300x237.png 300w\" sizes=\"(max-width: 516px) 100vw, 516px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h2>\u30b3\u30fc\u30c9\u5b9f\u88c5<\/h2>\n<p>MainViewController.swift\u3092\u65b0\u305f\u306b\u4f5c\u6210\u3057\u3001Storyboard\u306e\u6700\u521d\u306eViewController\u3068\u7d10\u4ed8\u3051\u3002<\/p>\n<p>MainViewController.swift\u306b\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u5b9f\u88c5<\/p>\n<pre class=\"lang:default decode:true \">class MainViewController: UIViewController, UIPageViewControllerDataSource, UIPageViewControllerDelegate {\r\n \r\n let idList: [String] = [\"first\", \"second\"]\r\n \r\n var pageViewController: UIPageViewController!\r\n var viewControllers: [UIViewController] = []\r\n \r\n @IBOutlet weak var selectTab: UISegmentedControl!\r\n \r\n override func viewDidLoad() {\r\n  super.viewDidLoad()\r\n \r\n  selectTab.setTitle(\"\uff11\u679a\u76ee\", forSegmentAt: 0)\r\n  selectTab.setTitle(\"\uff12\u679a\u76ee\", forSegmentAt: 1)\r\n \r\n  for id in idList {\r\n   viewControllers.append((storyboard?.instantiateViewController(withIdentifier: id))!)\r\n  }\r\n \r\n  pageViewController = childViewControllers[0] as! UIPageViewController\r\n  pageViewController.setViewControllers([viewControllers[0]], direction: .forward, animated: true, completion: nil)\r\n  pageViewController.dataSource = self\r\n  pageViewController.delegate = self\r\n }\r\n \r\n override func didReceiveMemoryWarning() {\r\n  super.didReceiveMemoryWarning()\r\n }\r\n \r\n func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -&gt; UIViewController? {\r\n  let index = idList.index(of: viewController.restorationIdentifier!)!\r\n  if (index &gt; 0) {\r\n   return storyboard!.instantiateViewController(withIdentifier: idList[index - 1])\r\n  }\r\n   return nil\r\n }\r\n \r\n func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -&gt; UIViewController? {\r\n  let index = idList.index(of: viewController.restorationIdentifier!)!\r\n  if (index &lt; idList.count - 1) {\r\n   return storyboard!.instantiateViewController(withIdentifier: idList[index + 1])\r\n  }\r\n  return nil\r\n }\r\n \r\n func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) {\r\n  let index = idList.index(of: (pageViewController.viewControllers?.first!.restorationIdentifier)!)\r\n  self.selectTab.selectedSegmentIndex = index!\r\n }\r\n \r\n @IBAction func selectedTab(_ sender: UISegmentedControl) {\r\n  switch sender.selectedSegmentIndex {\r\n   case 0:\r\n    pageViewController.setViewControllers([viewControllers[0]], direction: .reverse, animated: true, completion: nil)\r\n    break\r\n   case 1:\r\n    pageViewController.setViewControllers([viewControllers[1]], direction: .forward, animated: true, completion: nil)\r\n    break\r\n   default:\r\n    return\r\n   }\r\n }\r\n \r\n}<\/pre>\n<p>&nbsp;<\/p>\n<p>\u3053\u308c\u3067\u753b\u9762\u3092\u30d5\u30ea\u30c3\u30af\u3059\u308b\u304b\u30bb\u30b0\u30e1\u30f3\u30c8\u30dc\u30bf\u30f3\u3092\u62bc\u3059\u3053\u3068\u3067\u753b\u9762\u3092\u5207\u308a\u66ff\u3048\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u74b0\u5883\uff1axcode9 , swift4 \u30cb<\/p>\n","protected":false},"author":1,"featured_media":1384,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts\/1382"}],"collection":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/comments?post=1382"}],"version-history":[{"count":3,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts\/1382\/revisions"}],"predecessor-version":[{"id":1485,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts\/1382\/revisions\/1485"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/media\/1384"}],"wp:attachment":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/media?parent=1382"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/categories?post=1382"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/tags?post=1382"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}