Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically set UIPageViewController Transition Style to Scroll

Tags:

ios

swift

ios8

I am using Xcode 6 and implementing UIPageViewController for my app. I followed appcoda's tutorial, and everything works except the page indicators. This is because I cannot set the transition style of UIPageViewController to scroll.

Graphically, when I click on the PageViewController, the tab shows View Controller instead of Page View Controller like appcoda (See its image below)

enter image description here

This is what mine looks like:

enter image description here

And yes, my custom class is set to: UIPageViewController as it is in the tutorial. enter image description here

Programmatically, I try to set the transition style with:

    self.pageViewController.transitionStyle = UIPageViewControllerTransitionStyle.Scroll 

but it fails to build, telling me that it Could not find member transition style. One last weird thing I would like to point out is that if I just write self.pageViewController.transitionStyle, it builds successfully, but it still uses the Page Curl Transition.

Could anyone help me? I am using Swift, Xcode 6, and developing on the iOS 8 SDK.

like image 353
sameetandpotatoes Avatar asked Jul 04 '14 15:07

sameetandpotatoes


2 Answers

You're getting an error because transitionStyle is a readonly property. If you want to set the transition style of the page controller programmatically, it can only be done during initialization with the method:

init(transitionStyle style: UIPageViewControllerTransitionStyle, navigationOrientation navigationOrientation: UIPageViewControllerNavigationOrientation, options options: [NSObject : AnyObject]!) { ... } 

More info in the documentation.

like image 200
Mick MacCallum Avatar answered Sep 18 '22 03:09

Mick MacCallum


The issue is that when you create a UIPageViewController inside a Container, the container is first created with a UIViewController, and that s the controller you see your options for.

In order to fix it you have to delete UIViewController where you set your custom UIPageViewController. Then drag UIPageViewController from the controls picker and hook up the embed segue from the container to that controller, then you can set your custom pager controller as well as set transition to scroll.

like image 38
Marcin D Avatar answered Sep 18 '22 03:09

Marcin D