Pageviewcontroller and Uipagecontrol

Source: Internet
Author: User

Used to take these two things as one thing, Pageviewcontroller like e-book, a page can put a few childviewcontroller, and then turn around, the current frame shows a few viewcontroller. Uipagecontrol with ScrollView is used to slide the page left and right, the current frame only shows a viewcontroller.

Page View Controllers
You use a Page view controller to display content in a page by page way. A Page view controller manages a self-contained view schema. The parent view of this schema is managed by the Page view controller, and the child view is managed by the view controllers that you provide.

One, parse page View Controller
A page view controller has a separate view that is where your content is stored.
Shows the structure of Page view interface: The outermost brown view is the parent view controller, not the page view controllers themselves. The page view controller does not have its own UI; However, it makes a page-turn effect on its children.

Two, Page view Controller Interface object:
An optional proxy, an optional data source, a set of current view controllers, a set of gesture recognizers

The data source provides viewcontrollers on demand.
Delegates provide responses to gesture-based navigation and direction changes.
The array of view controllers contains the content view controller that is currently being displayed. The number of items in the array is based on the options passed to the Page view controller.
a gesture recognizer exists only if the data source is specified. These gesture recognizers use the user to flick, flicking (swipe), or drag to page.

Three, create Page view Controller interface:
The view of Page view controller can be scaled and embedded in a view hierarchy. This means that unlike a navigation controller or tab bar, Controller,page View controller can be used in a wide range of situations, rather than in some special cases.

1, create a new project with Page view controller by creating a Page view controller:page-based application Xcode template with Stroyboard.
To add a page view controller to an already existing storyboard:
1) Drag a Page view controller and add a page view controller scene to your storyboard.
2) In the property inspector, set the appropriate options.
3) Optionally, set a delegate, data source
4) ...

2, create a Page view controller from the code:
1) Create a page view controller by using the InitWithTransitionStyle:navigationOrientation:options: method
2) Optionally, set up an agent, data source
3) Set the initial content view controllers
4) Display the Page view controller's view on the screen.

3, set the original view controller: Whether you create a page view controller through code or through IB, you need to specify an initial view controller before displaying it to the screen.
Call SetViewControllers:direction:animated:completion: Method.

If the page view controller does not have a initial view controller, its shouldautorotatetointerfaceorientation: Returns no, and throws an exception.

Four, custom initialization behavior:
At initialization, you pass the parameter values and options to the InitWithTransitionStyle:navigationOrientation:options: method to customize a Page view controller. After initialization, these properties are read-only. You can customize:
1) The direction in which navigation occurs.
2) The location of the spine. (Position of spine)
3) the transition style. In IOS 5, the-valid transition style is uipageviewcontrollertransitionstylepagecurl.

For example

Listing 3-1 Customizing a Page view Controller
nsdictionary * options = [nsdictionary dictionarywithobject:[nsnumber numberwithint: Uipageviewcontrollerspinelocationmid] Forkey:uipageviewcontrolleroptionspinelocationkey];

Uipageviewcontroller *pageviewcontroller = [[Uipageviewcontroller alloc]initwithtransitionstyle: Uipageviewcontrollertransitionstylepagecurl navigationorientation: Uipageviewcontrollernavigationorientationhorizontal Options:options];

V. Use proxy custom behavior at run time:
Uipageviewcontrollerdelegate protocol: You can perform an action when the device orientation changes and the user navigates to a new page, and it can update the position of the spine to respond to a shift in direction.

Vi. provision of content through data sources:
The method of the data source is called by the view controller that is currently displayed and returns the view controller before and after it. To simplify the search for the front and back Viewcontroller, you can store additional information in your view controller, such as a page number.
If a data source is specified, the Page view controller identifies the associated gesture to its view. These gestures are accessed through the Gesturerecognizers property.

To move a gesture to recognize another view, pass the value of the Gesturerecognizers property to the Addgesturerecognizer: method of the target view.

For example, if your Page view controller is not filled with a screen, you pass the gesture recognition to its superview, and you can turn the page better without having to page through the Page view controller.

Seven, provide content by setting up the current View controller:
SetViewControllers:direction:animated:completion: Method directly controls which content is displayed.
If you don't have a data source set up, you'll need to provide the UI to move pages, such as Forward and back buttons. Gesture-driven navigation is available only when you provide a data source.

Eight, special consideration Right-to-left and Bottom-to-top Content:
To use a Page view controller to display a right-to-left or bottom-to-top content through a data source, you only need to reverse the implementation of the following two methods:
1) in your data source, implement Pageviewcontroller:viewcontrollerbeforeviewcontroller: and return to the Viewcontroller
2) Pageviewcontroller:viewcontrollerafterviewcontroller: Return to the previous viewcontroller>

And, you generally have to set the spine position to Uipageviewcontrollerspinelocationmax

Pageviewcontroller and Uipagecontrol

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.