Search code examples
swiftxcodeuipageviewcontroller

How to programmatically set the transition style of a UIPageViewController in swift, Xcode?


I am trying to make a UIPageviewController programmatically without using the storyboard, I know that there is an option on the storyboard to set the transition style, but I won't be able to do this. I basically want to set the transition style to page scroll within the code.

I have tried many things, but nothing has worked.


Solution

  • Do it in the initialization, before your viewDidLoad() function:

    override init(transitionStyle style: 
    UIPageViewControllerTransitionStyle, navigationOrientation: UIPageViewControllerNavigationOrientation, options: [String : Any]? = nil) {
        super.init(transitionStyle: .whatever_style, navigationOrientation: .horizontal, options: nil)
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }