iOS Developer Library — Pre-Release

Developer

UIKit Framework Reference UIPageViewController Class Reference

Options
Deployment Target:

On This Page
Language:

UIPageViewController

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.

Inheritance


Import Statement


Swift

import UIKit

Objective-C

@import UIKit;

Availability


Available in iOS 5.0 and later.
  • Sets the view controllers to be displayed.

    Declaration

    Swift

    func setViewControllers(_ viewControllers: [AnyObject]!, direction direction: UIPageViewControllerNavigationDirection, animated animated: Bool, completion completion: ((Bool) -> Void)!)

    Objective-C

    - (void)setViewControllers:(NSArray *)viewControllers direction:(UIPageViewControllerNavigationDirection)direction animated:(BOOL)animated completion:(void (^)(BOOL finished))completion

    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

    YEStrue if the animation finished; NOfalse if 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

    UIPageViewControllerSpineLocationMid

    YEStrue

    Pass the page to be displayed on the left and the page to be displayed on the right.

    UIPageViewControllerSpineLocationMin or UIPageViewControllerSpineLocationMax

    YEStrue

    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.

    UIPageViewControllerSpineLocationMin or UIPageViewControllerSpineLocationMax

    NOfalse

    Pass the front of the page to be displayed.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 5.0 and later.

    See Also

    viewControllers

  • The view controllers displayed by the page view controller. (read-only)

    Declaration

    Swift

    var viewControllers: [AnyObject]! { get }

    Objective-C

    @property(nonatomic, readonly) NSArray *viewControllers

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 5.0 and later.

  • An array of UIGestureRecognizer objects that are configured to handle user interaction. (read-only)

    Declaration

    Swift

    var gestureRecognizers: [AnyObject] { get }

    Objective-C

    @property(nonatomic, readonly) NSArray *gestureRecognizers

    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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 5.0 and later.

  • The direction along which navigation occurs. (read-only)

    Declaration

    Swift

    var navigationOrientation: UIPageViewControllerNavigationOrientation { get }

    Objective-C

    @property(nonatomic, readonly) UIPageViewControllerNavigationOrientation navigationOrientation

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 5.0 and later.

  • The location of the spine. (read-only)

    Declaration

    Swift

    var spineLocation: UIPageViewControllerSpineLocation { get }

    Objective-C

    @property(nonatomic, readonly) UIPageViewControllerSpineLocation spineLocation

    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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 5.0 and later.

  • The style used to transition between view controllers. (read-only)

    Declaration

    Swift

    var transitionStyle: UIPageViewControllerTransitionStyle { get }

    Objective-C

    @property(nonatomic, readonly) UIPageViewControllerTransitionStyle transitionStyle

    Discussion

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

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 5.0 and later.

  • A Boolean value that indicates whether content appears on the back of pages.

    Declaration

    Swift

    var doubleSided: Bool

    Objective-C

    @property(nonatomic, getter=isDoubleSided) BOOL doubleSided

    Discussion

    The default value for this property is NOfalse.

    If the back of pages has no content (the value is NOfalse), 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 YEStrue. Setting it to NOfalse with the spine located in the middle raises an exception.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 5.0 and later.

  • Orientations for page-turn transitions.

    Declaration

    Swift

    enum UIPageViewControllerNavigationOrientation : Int { case Horizontal case Vertical }

    Objective-C

    enum { UIPageViewControllerNavigationOrientationHorizontal = 0, UIPageViewControllerNavigationOrientationVertical = 1 }; typedef NSInteger UIPageViewControllerNavigationOrientation;

    Constants

    • Horizontal

      UIPageViewControllerNavigationOrientationHorizontal

      Horizontal orientation, with pages turning left and right.

      Available in iOS 5.0 and later.

    • Vertical

      UIPageViewControllerNavigationOrientationVertical

      Vertical orientation, with pages turning up and down.

      Available in iOS 5.0 and later.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 5.0 and later.

  • Directions for page-turn transitions.

    Declaration

    Swift

    enum UIPageViewControllerNavigationDirection : Int { case Forward case Reverse }

    Objective-C

    enum { UIPageViewControllerNavigationDirectionForward, UIPageViewControllerNavigationDirectionReverse }; typedef NSInteger UIPageViewControllerNavigationDirection;

    Constants

    • Forward

      UIPageViewControllerNavigationDirectionForward

      Navigation to the next page.

      Available in iOS 5.0 and later.

    • Reverse

      UIPageViewControllerNavigationDirectionReverse

      Navigation to the previous page.

      Available in iOS 5.0 and later.

    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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 5.0 and later.

  • Styles for the page-turn transition.

    Declaration

    Swift

    enum UIPageViewControllerTransitionStyle : Int { case PageCurl case Scroll }

    Objective-C

    enum { UIPageViewControllerTransitionStylePageCurl = 0 UIPageViewControllerTransitionStyleScroll = 1 }; typedef NSInteger UIPageViewControllerTransitionStyle;

    Constants

    • PageCurl

      UIPageViewControllerTransitionStylePageCurl

      Page 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.

    • Scroll

      UIPageViewControllerTransitionStyleScroll

      Scrolling 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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 5.0 and later.

  • Keys for the options dictionary.

    Declaration

    Swift

    let UIPageViewControllerOptionSpineLocationKey: String let UIPageViewControllerOptionInterPageSpacingKey: String

    Objective-C

    NSString * const UIPageViewControllerOptionSpineLocationKey; NSString * const UIPageViewControllerOptionInterPageSpacingKey;

    Constants

    • UIPageViewControllerOptionSpineLocationKey

      UIPageViewControllerOptionSpineLocationKey

      Location 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 is UIPageViewControllerSpineLocationMin; otherwise, the default is UIPageViewControllerSpineLocationNone.

      Available in iOS 5.0 and later.

    • UIPageViewControllerOptionInterPageSpacingKey

      UIPageViewControllerOptionInterPageSpacingKey

      Space between pages, in points.

      The value should be a CGFloat wrapped in an instance of NSNumber. The default value is zero. An inter-page spacing is only valid if the transition style is UIPageViewControllerTransitionStyleScroll.

      Available in iOS 6.0 and later.

  • Locations for the spine.

    Declaration

    Swift

    enum UIPageViewControllerSpineLocation : Int { case None case Min case Mid case Max }

    Objective-C

    enum { UIPageViewControllerSpineLocationNone = 0, UIPageViewControllerSpineLocationMin = 1, UIPageViewControllerSpineLocationMid = 2, UIPageViewControllerSpineLocationMax = 3 }; typedef NSInteger UIPageViewControllerSpineLocation;

    Constants

    • None

      UIPageViewControllerSpineLocationNone

      No spine.

      This spine location is not valid if the transition style is UIPageViewControllerTransitionStylePageCurl.

      Available in iOS 5.0 and later.

    • Min

      UIPageViewControllerSpineLocationMin

      Spine at the left or top edge of the screen.

      One view controller is displayed at a time.

      Available in iOS 5.0 and later.

    • Mid

      UIPageViewControllerSpineLocationMid

      Spine in the middle or the screen.

      Two view controllers are displayed at a time.

      Available in iOS 5.0 and later.

    • Max

      UIPageViewControllerSpineLocationMax

      Spine at the right or bottom edge of the screen.

      One view controller is displayed at a time.

      Available in iOS 5.0 and later.

    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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 5.0 and later.