Help us understand the problem. What is going on with this article?

[WIP]UIPageViewController

More than 3 years have passed since last update.

RootViewController
ModelController

RootViewController

self.pageViewController = UIPageViewController(transitionStyle: .Scroll, navigationOrientation: .Horizontal, options: nil)

UIPageViewControllerDelegate プロトコルを実装する
transitionStyle:スライド式か、ページめくり方式か設定できる

.PageCurl : ページめくり方式
.Scroll : スライド式

navigationOrientation:

.Horizontal :よこめくり
.Vertical : たてめくり

self.pageViewController!.delegate = self

pageViewControllerのデリゲートになる

let startingViewController: DataViewController = self.modelController.viewControllerAtIndex(0, storyboard: self.storyboard!)!

startingViewControllerを定数で定義する。
viewControllerAtIndex(0, storyboard: self.storyboard!)!は、modelControllerのメソッドで、
第一引数の数字(index)に該当するDataViewControllerを生成して、返すメソッド。ここでは0番目(初期値)で生成をしている。
storyboardを渡してあげ,メソッド内でストーリーボードのinstantiateViewControllerWithIdentifierを呼び出すことで、ストーリーボードにDataViewControlellerを追加することができる。

var modelController: ModelController {
        // Return the model controller object, creating it if necessary.
        // In more complex implementations, the model controller may be passed to the view controller.
        if _modelController == nil {
            _modelController = ModelController()
        }
        return _modelController!
    }

    var _modelController: ModelController? = nil

modelControllerは,
・インスタンス化されていればその参照を返す
・されていなければ、インスタンス化し参照を返す
関数で下記に定義されている

let viewControllers: NSArray = [startingViewController]

初期値画面のstartingViewControllerが入った配列(定数)を定義

self.pageViewController!.setViewControllers(viewControllers, direction: .Forward, animated: false, completion: {done in })

配列を、pageViewControllerのViewControllersに設定する。

self.pageViewController!.dataSource = self.modelController

        self.addChildViewController(self.pageViewController!)
        self.view.addSubview(self.pageViewController!.view)

データソースはmodelControlerにする
自信の子ViewControllerに、pageViewControllerを追加
自信のViewに、pageViewControllerのViewを追加

var pageViewRect = self.view.bounds
self.pageViewController!.view.frame = pageViewRect
 self.pageViewController!.didMoveToParentViewController(self)

めくっているとき、後ろにもとのViewが見えるようにする

self.view.gestureRecognizers = self.pageViewController!.gestureRecognizers


自信のジェスチャーレコグナイザに、pageViewControllerのジェスチャを追加

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away