IPhone/IOS uiviewcontroller-uipageviewcontroller (ios5 only)

Source: Internet
Author: User

I. Basic parameters and composition

Datasource provides data sources

Delegate tracks gesture and device direction changes

Viewcontrollers can display up to two view controllers on the current screen. This is read-only. To set viewcontrollers, call the corresponding setviewcontrollers.

Guesturrecognizers: Gesture Recognition. You can add related gestures to a larger view, for example, parentview of pageviewcontroller. View.

Ii. Create

Self. window = [[[uiwindow alloc] initwithframe: [[uiscreen mainscreen] bounds] autorelease]; // you must set the position of the spine during creation. Valid parameters include Max, Min, mid, where mid requires two nsdictionary * Options = [nsdictionary dictionarywithobject: [nsnumber numberwithint: uipageviewcontrollerspinelocationmid] forkey: Custom]; // transitionstyle has only one; navigationorientation indicates uipageviewcontroller * pageviewcontroller = [[uipageviewcontroller alloc] initwithtransitionstyle: uipageviewcontrollertransitionstylepagecurl navigationorientation: customization options: Options]; self. viewcontroller = [[[fcdemoviewcontroller alloc] handler: @ "fcdemoviewcontroller" Bundle: Nil] autorelease]; firstview * First = [[[firstview alloc] initwithnibname: @ "firstview" Bundle: nil] autorelease]; // set initial content controller. The set array must be based on the position of the spine. If it is 2 pages, it must be 2 controllers //, if initial controller is not set correctly, a shouldautorotatetointerfaceorientation error [pageviewcontroller setviewcontrollers: [nsarray arraywithobjects: Self. viewcontroller, first, nil] direction: uipageviewcontrollernavigationorientationhorizontal animated: Yes completion: Nil]; demodatasource * snd = [[demodatasource alloc] init]; pageviewcontroller. datasource = SND; demodelegate * del = [[demodelegate alloc] init]; pageviewcontroller. delegate = del; pageviewcontroller. view. gesturerecognizers = pageviewcontroller. gesturerecognizers; self. window. rootviewcontroller = pageviewcontroller;

The related settings and parameters have been basically set. The relevant explanations are in the annotations,

It is worth noting that datasource is set. In addition, datasource should be a custom class that directly inherits nsobject.

In addition, you also need to set initial content to set viewcontrollers, because this is the display of the first page of content.

3. Set content

1. Set in datasource

Declaration class:

@interface DemoDataSource : NSObject<UIPageViewControllerDataSource>

Implementation Method:

-(UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController{                  Second *cons= [[[Second alloc] initWithNibName:@"Second" bundle:nil] autorelease];        return cons;}-(UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController{               Second *cons= [[[Second alloc] initWithNibName:@"Second" bundle:nil] autorelease];        return cons;}

It is worth mentioning that if you want to flip the book in the opposite direction, that is, from the left to the right is the next page, you need to reverse the two methods of providing the content to the provided viewcontroller.

2. Set initial view controller directly

This is generally used for jump, for example, to jump from a page to another page.

Iv. Proxy Methods

-(Void) pageviewcontroller :( uipageviewcontroller *) pageviewcontroller preview :( bool) finished previusviewcontrollers :( nsarray *) specify transitioncompleted :( bool) completed {}// adjust the position of the spine after the orientation changes are provided, generally, the horizontal screen is mid, divided into two pages, vertical screen min, divided into one page-(uipageviewcontrollerspinelocation) pageviewcontroller :( uipageviewcontroller *) pageviewcontroller spinelocationforinterfaceorientation :( uiinterfaceorientation) orientation {If (uiinterfaceorientationislandscape (orientation) {return uipageviewcontrollerspinelocationmid;} else {return uipageviewcontrollerspinelocationmin ;}}

Related Article

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: info-contact@alibabacloud.com 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.