UIPageViewController Class Reference
| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/UIKit.framework |
| Availability | Available in iOS 5.0 and later. |
| Companion guide | |
| Declared in | UIPageViewController.h |
Overview
A page view controller lets the user navigate between pages of content, where each page is managed by its own view controller object. Navigation can be controlled programmatically by your app or directly by the user using gestures. When navigating from page to page, the page view controller uses the transition that you specify to animate the change.
When defining a page view controller interface, you can provide the content view controllers one at a time (or two at a time, depending upon the spine position and double-sided state) or as-needed using a data source. When providing content view controllers one at a time, you use the setViewControllers:direction:animated:completion: method to set the current content view controllers. To support gesture-based navigation, you must provide your view controllers using a data source object.
The data source for a page view controller is responsible for providing the content view controllers on demand and must conform to the UIPageViewControllerDataSource protocol. The delegate object—an object that conforms to the UIPageViewControllerDelegate protocol—provides some appearance-related information and receives notifications about gesture-initiated transitions.
This class is generally used as-is but may be subclassed in iOS 6 and later.
Tasks
Creating Page View Controllers
-
– initWithTransitionStyle:navigationOrientation:options: -
dataSourceproperty -
delegateproperty
Providing Content
-
– setViewControllers:direction:animated:completion: -
viewControllersproperty -
gestureRecognizersproperty
Display Options
-
navigationOrientationproperty -
spineLocationproperty -
transitionStyleproperty -
doubleSidedproperty
Properties
dataSource
The object that provides view controllers.
Discussion
Methods of the data source are called in response to gesture-based navigation. If the value of this property is nil, then gesture-based navigation is disabled.
Availability
- Available in iOS 5.0 and later.
Declared In
UIPageViewController.hdelegate
The delegate object.
Discussion
Methods of the delegate are called in response to gesture-based navigation and orientation changes.
Availability
- Available in iOS 5.0 and later.
Declared In
UIPageViewController.hdoubleSided
A Boolean value that indicates whether content appears on the back of pages.
Discussion
The default value for this property is NO.
If the back of pages has no content (the value is NO), then the content on the front of the page will partially show through to the back when turning pages.
If the spine is located in the middle, the value must be YES. Setting it to NO with the spine located in the middle raises an exception.
Availability
- Available in iOS 5.0 and later.
Declared In
UIPageViewController.hgestureRecognizers
An array of UIGestureRecognizer objects that are configured to handle user interaction. (read-only)
Discussion
These gesture recognizers are initially attached to a view in the page view controller’s hierarchy. To change the region of the screen in which the user can navigate using gestures, they can be placed on another view.
Availability
- Available in iOS 5.0 and later.
Declared In
UIPageViewController.hnavigationOrientation
The direction along which navigation occurs. (read-only)
Availability
- Available in iOS 5.0 and later.
Declared In
UIPageViewController.hspineLocation
The location of the spine. (read-only)
Discussion
The value of this property is set with the UIPageViewControllerOptionSpineLocationKey key when the page view controller is initialized, and can be changed by returning the new value from the pageViewController:spineLocationForInterfaceOrientation: method of the delegate.
Availability
- Available in iOS 5.0 and later.
Declared In
UIPageViewController.htransitionStyle
The style used to transition between view controllers. (read-only)
Discussion
The value of this property is set when the page view controller is initialized, and cannot be changed.
Availability
- Available in iOS 5.0 and later.
Declared In
UIPageViewController.hviewControllers
The view controllers displayed by the page view controller. (read-only)
Availability
- Available in iOS 5.0 and later.
Declared In
UIPageViewController.hInstance Methods
initWithTransitionStyle:navigationOrientation:options:
Initializes a newly created page view controller.
Parameters
- style
The style for transitions between pages.
- navigationOrientation
The orientation of the page-by-page navigation.
- options
A dictionary of options. For keys, see “Options Keys.”
Return Value
The initialized page view controller.
Discussion
After initialization, use the setViewControllers:direction:animated:completion: method to set the initial view controllers.
Availability
- Available in iOS 5.0 and later.
Declared In
UIPageViewController.hsetViewControllers:direction:animated:completion:
Sets the view controllers to be displayed.
Parameters
- viewControllers
The view controller or view controllers to be displayed.
- direction
The navigation direction.
- animated
A Boolean value that indicates whether the transition is to be animated.
- completion
A block to be called when the page-turn animation completes.
The block takes the following parameters:
- finished
YESif the animation finished;NOif it was skipped.
Discussion
The view controllers passed to this method are those that will be visible after the animation has completed. Use a data source to provide additional view controllers to which users navigate.
If the transition style is UIPageViewControllerTransitionStylePageCurl, the view controllers to pass in the viewControllers parameter depends on the spine location and the value of the doubleSided property:
Spine location | Double sided | What to pass |
|---|---|---|
|
| Pass the page to be displayed on the left and the page to be displayed on the right. |
|
| Pass the front of the page to be displayed and the back of the previously-displayed page. The back is used for the page turning animation. |
|
| Pass the front of the page to be displayed. |
Availability
- Available in iOS 5.0 and later.
See Also
Declared In
UIPageViewController.hConstants
Navigation Orientations
Orientations for page-turn transitions.
enum {
UIPageViewControllerNavigationOrientationHorizontal = 0,
UIPageViewControllerNavigationOrientationVertical = 1
};
typedef NSInteger UIPageViewControllerNavigationOrientation;
Constants
UIPageViewControllerNavigationOrientationHorizontalHorizontal orientation, with pages turning left and right.
Available in iOS 5.0 and later.
Declared in
UIPageViewController.h.UIPageViewControllerNavigationOrientationVerticalVertical orientation, with pages turning up and down.
Available in iOS 5.0 and later.
Declared in
UIPageViewController.h.
Navigation Directions
Directions for page-turn transitions.
enum {
UIPageViewControllerNavigationDirectionForward,
UIPageViewControllerNavigationDirectionReverse
};
typedef NSInteger UIPageViewControllerNavigationDirection;
Constants
UIPageViewControllerNavigationDirectionForwardNavigation to the next page.
Available in iOS 5.0 and later.
Declared in
UIPageViewController.h.UIPageViewControllerNavigationDirectionReverseNavigation to the previous page.
Available in iOS 5.0 and later.
Declared in
UIPageViewController.h.
Discussion
For horizontal navigation, pages turn from the right side of the screen to the left as you navigate forward.
For vertical navigation, pages turn from the bottom of the screen to the top as you navigate forward.
Transition Styles
Styles for the page-turn transition.
enum {
UIPageViewControllerTransitionStylePageCurl = 0
UIPageViewControllerTransitionStyleScroll = 1
};
typedef NSInteger UIPageViewControllerTransitionStyle;
Constants
UIPageViewControllerTransitionStylePageCurlPage curl transition style.
When the page curl transition style is specified, the page view controller displays a page-turning animation when transitioning between view controllers. If a data source is specified, the animation follows the user’s finger during a navigation gesture.
Available in iOS 5.0 and later.
Declared in
UIPageViewController.h.UIPageViewControllerTransitionStyleScrollScrolling transition style.
When the page scrolling style is specified, the page view controller displays a page-scrolling animation when transitioning between view controllers. If a data source is specified, the animation follows the user’s finger during a navigation gesture.
Available in iOS 6.0 and later.
Declared in
UIPageViewController.h.
Options Keys
Keys for the options dictionary.
NSString * const UIPageViewControllerOptionSpineLocationKey; NSString * const UIPageViewControllerOptionInterPageSpacingKey;
Constants
UIPageViewControllerOptionSpineLocationKeyLocation of the spine.
For possible values, see “Spine Locations.” A spine location is only valid if the transition style is
UIPageViewControllerTransitionStylePageCurl.If the transition style is
UIPageViewControllerTransitionStylePageCurl, the default value for this property isUIPageViewControllerSpineLocationMin; otherwise, the default isUIPageViewControllerSpineLocationNone.Available in iOS 5.0 and later.
Declared in
UIPageViewController.h.UIPageViewControllerOptionInterPageSpacingKeySpace between pages, in points.
The value should be a
CGFloatwrapped in an instance ofNSNumber. The default value is zero. An inter-page spacing is only valid if the transition style isUIPageViewControllerTransitionStyleScroll.Available in iOS 6.0 and later.
Declared in
UIPageViewController.h.
Discussion
See also initWithTransitionStyle:navigationOrientation:options:.
Spine Locations
Locations for the spine.
enum {
UIPageViewControllerSpineLocationNone = 0,
UIPageViewControllerSpineLocationMin = 1,
UIPageViewControllerSpineLocationMid = 2,
UIPageViewControllerSpineLocationMax = 3
};
typedef NSInteger UIPageViewControllerSpineLocation;
Constants
UIPageViewControllerSpineLocationNoneNo spine.
This spine location is not valid if the transition style is
UIPageViewControllerTransitionStylePageCurl.Available in iOS 5.0 and later.
Declared in
UIPageViewController.h.UIPageViewControllerSpineLocationMinSpine at the left or top edge of the screen.
One view controller is displayed at a time.
Available in iOS 5.0 and later.
Declared in
UIPageViewController.h.UIPageViewControllerSpineLocationMidSpine in the middle or the screen.
Two view controllers are displayed at a time.
Available in iOS 5.0 and later.
Declared in
UIPageViewController.h.UIPageViewControllerSpineLocationMaxSpine at the right or bottom edge of the screen.
One view controller is displayed at a time.
Available in iOS 5.0 and later.
Declared in
UIPageViewController.h.
Discussion
To set the spine location, wrap one of these constants in an NSNumber object and set it as the value for the UIPageViewControllerOptionSpineLocationKey key in the options dictionary passed to the initWithTransitionStyle:navigationOrientation:options: method.
© 2012 Apple Inc. All Rights Reserved. (Last updated: 2012-12-13)