LoginSignup
6
9

More than 5 years have passed since last update.

[WIP]UIPageViewController

Last updated at Posted at 2015-01-28

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のジェスチャを追加

6
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
9