UIPageViewControllerで左右のビューを作りたい
https://hajihaji-lemon.com/swift/spine-location/
を参考にした。 Storyboardを使った。
override func viewDidLoad() { super.viewDidLoad() // spineLocationを.midに設定して、見開きで表示 self.spineLocation = .mid let leftViewController = UIViewController() let rightViewController = UIViewController() self.setViewControllers([leftViewController, rightViewController], direction: .forward, animated: true, completion: nil) }
みたいにしたいが、 まず
self.spineLocation = .mid
が設定できない、 readonly
だ・・・
これはStoryboardでやるとしてコメントアウトした。
さらに、
Thread 1: "The number of view controllers provided (2) doesn't match the number required (1) for the requested transition"のエラーが発生した
が発生する。
これは、storyboardで、SpineLocation
を Mid
にしたんだが??
サイトを見たら
1つのビューコントローラーを本の1ページとしたときの本の背の位置を「None」、「Min」、「Mid」、「Max」から選択する。この設定はTransition Styleが「Page Curl」のときのみ有効になる。
とあったので
みたく、「Page Curl」も設定が必須!
transitionStyle も readonly
なのでコードでは設定できなかった。
みたいに UIPageViewController
を継承したViewを設定したほうがいいかもしれない。
コードでは init
をこのようにしたらいけた
init() { let options = [UIPageViewController.OptionsKey.spineLocation : NSNumber(value: UIPageViewController.SpineLocation.mid.rawValue)] super.init(transitionStyle: .pageCurl, navigationOrientation: .horizontal, options: options) } required init?(coder aDecoder: NSCoder) { let options = [UIPageViewController.OptionsKey.spineLocation : NSNumber(value: UIPageViewController.SpineLocation.mid.rawValue)] super.init(transitionStyle: .pageCurl, navigationOrientation: .horizontal, options: options) }