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:
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)
}
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.
Related Topics
iOS Healthkit How to Save Heart Rate (Bpm) Values? Swift
(Swift Spritekit) Rotate Sprite in the Direction of Touch
Avmutablevideocomposition Output Video Shrinked
How to Automatically Create an Initializer for a Swift Class
Today Extension with Uicollectionview Different Behaviour Compared to Single View Application
How to Make a Bullet List with Swift
Avcapturestillimageoutput VS Avcapturephotooutput in Swift 3
Swift Get Specific Value from Firebase Database
iOS with Parse. Pfuser.Currentuser() Not Getting Cached. Returns Nil After App Restart
Endless Scrolling (Repeating) Background in Spritekit Game - Swift
iOS - Send Image to Instagram - Documentinteraction
App Groups Forsecurityapplicationgroupidentifier Returns Nil
Setting Uiimageview Image Affects Layout Constraints
iOS Swift Connect Wifi Programmatically and Distinguish Between Bad Password and No Wifi in Range