Programmatically Set Uipageviewcontroller Transition Style to Scroll

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

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")
}

swift ios Set transition style and orientation programmatically of PageViewController

from where we call this page view controller for example on a button click method you can initialize just like this

let vc = YourPageViewController(transitionStyle: 
UIPageViewControllerTransitionStyle.scroll, navigationOrientation:
UIPageViewControllerNavigationOrientation.horizontal, options: nil)
self.present(vc, animated: true, completion: nil)

and in YourPageViewController you can implement initializer

override init(transitionStyle style: UIPageViewControllerTransitionStyle, navigationOrientation: UIPageViewControllerNavigationOrientation, options: [String : Any]? = nil) {
super.init(transitionStyle: style, navigationOrientation: navigationOrientation, options: nil)
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

the values passed from button click action will be set and you will have horizontal orientation and scroll transition style

Transition PageCurl to Scroll with UIPageViewController

From the Apple Docs:

"The value of this property is set when the page view controller is initialized, and cannot be changed."

You must specify the transition style when you initialize. If you do that in code, you will need something like:

let pageViewController = ViewController(transitionStyle: .Scroll, navigationOrientation: .Horizontal, options: nil)

(Since ViewController is a subclass of UIPageViewController)

If you are setting up the Page View Controller in a storyboard, amend the transition style in the attributes inspector:

Image of attributes inspector

How do I get UIPageViewController to use Transition Style Scroll?

Just add init code and initialize transition style programmatically.

required init?(coder aDecoder: NSCoder) {
super.init(transitionStyle: .scroll, navigationOrientation: .horizontal, options: nil)
}

Sample Image

UIPageviewcontroller transition style scroll continuous

You cannot have a continuous scroll, what you can have is paginated scrolling meaning that the PageViewController will always snap to a particular page. See the types:

UIPageViewControllerTransitionStylePageCurl = 0, // Navigate between views via a page curl transition.
UIPageViewControllerTransitionStyleScroll

Perhaps what you are looking for is a UIScrollView or UICollectionView (Meaning you are going to need to write your own continuous scrolling component)

UIPageViewController Transition Style = Page curl works fine, Scroll throws index out of bounds?

In pageViewController(_:viewControllerBeforeViewController:) (frame #3), you call viewControllerAtIndex(currentIndex - 1) (frame #2) even when currentIndex is zero, so you're passing -1 to viewControllerAtIndex(_:). You should check for that in viewControllerAtIndex(_:). Something like this should do:

func viewControllerAtIndex(index: Int) -> UIViewController? {
if index < 0 || index >= (times?.count ?? 0) {
return nil
}

if let time = times?[index] {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("SinglePageViewController") as! SinglePageViewController
vc.time = time
return vc
}
return nil
}

Differing options for UIPageViewController.transitionStyle in Xcode GUI vs Programmatic Enum

You look at UIViewController's modal transition style not UIPageViewController's one. If you create UIPageViewController in Storyboard you'll see another transition style in "Page View Controller" block in Interface Builder.

About UIViewController's transition style you can read here.

Page View Controller



Related Topics



Leave a reply



Submit