IOS: Page Flipping effect

Source: Internet
Author: User

////main.m//Hello////Created by Lishujun on 14-8-28.//Copyright (c) 2014 Lishujun. All rights reserved.////paging too fast will be problematic, unresolved//unbalanced calls to begin/end appearance transitions for <contentviewcontroler:0x8f3d570>.#import<UIKit/UIKit.h>//-----------------------------The Content view Controller-----------------------------@interfaceContentviewcontroler:uiviewcontroller@property (nonatomic,strong) UILabel*label; @property NSString*message;@end@implementationContentviewcontroler@synthesizelabel;@synthesizeMessage =_message;-(ID) Initwithmessage: (NSString *) amessage{_message=amessage; returnSelf ;}-(void) viewdidload{//[Super Viewdidload]; //Create a Label objectlabel = [[UILabel alloc]initwithframe:cgrectmake (0.0,0.0,320.0,30.0)]; Label.text=_message; Label.center=Self.view.center; Label.textalignment=Uitextalignmentcenter; Label.backgroundcolor=[Uicolor Clearcolor]; Label.textcolor=[Uicolor Redcolor]; //add a label to a view[Self.view Addsubview:label]; Self.view.backgroundColor=[Uicolor Lightgraycolor];}-(void) Updatemessage: (nsstring*) amessage{_message=amessage; Label.text=_message;}@end//-----------------------------View Controller Object-----------------------------@interfaceMypageviewcontroller:uiviewcontroller <UIPageViewControllerDataSource>{    intPageIndex;} @property (Strong, nonatomic) Uipageviewcontroller*Pageviewcontroler, @property (Strong, nonatomic) Nsarray*Array;@end@implementationMypageviewcontroller@synthesizePageviewcontroler =_pageviewcontroler;@synthesizeArray =_array;-(void) viewdidload{[Super Viewdidload]; Self.view.frame= CGRectMake (0.0f,0.0f,320.0f,440.0f); Contentviewcontroler*content1 = [[Contentviewcontroler alloc]initwithmessage:@"Hello"]; Contentviewcontroler*content2 = [[Contentviewcontroler alloc]initwithmessage:@""]; Nsarray*array =@[content1]; NSLog (@"%@", Content1); _array=[[Nsarray alloc]initwithobjects:content1, Content2, nil]; _pageviewcontroler=[[Uipageviewcontroller alloc] Initwithtransitionstyle:uipageviewcontrollertransitionst                                               Ylepagecurl Navigationorientation:uipageviewcontrollernavigationorientationhorizontal        Options:nil]; [_pageviewcontroler Setviewcontrollers:array Direction:uipageviewcontrollernavigationdirec        Tionforward Animated:yes Completion:null]; _pageviewcontroler.datasource=Self ;    [Self addchildviewcontroller:_pageviewcontroler];        [Self.view Addsubview:_pageviewcontroler.view]; PageIndex=0;}//---------------The data source method------------------(Uiviewcontroller *) Pageviewcontroller: (Uipageviewcontroller*) Pageviewcontroller Viewcontrollerbeforeviewcontroller: (Uiviewcontroller*) viewcontroller{Contentviewcontroler*aviewcontroller = (contentviewcontroler*) [self changeviewcontroler:viewcontroller]; [Aviewcontroller updatemessage:@"i ' m lishujun too"]; returnAviewcontroller;}-(Uiviewcontroller *) Pageviewcontroller: (Uipageviewcontroller*) Pageviewcontroller Viewcontrollerafterviewcontroller: (Uiviewcontroller*) viewcontroller{Contentviewcontroler*aviewcontroller = (contentviewcontroler*) [self changeviewcontroler:viewcontroller]; [Aviewcontroller updatemessage:@"i ' m Lishujun"]; returnAviewcontroller;}//---A custom method to switch elements in an array of only two elements----(Uiviewcontroller *) Changeviewcontroler: (uiviewcontroller*) viewcontroller{intindex =[_array Indexofobject:viewcontroller]; Switch(index) { Case 0:            return_array[1];  Case 1:            return_array[0]; }    returnNil;}@end//-----------------------------The delegate object-------------------------------@interfaceHelloworldappdelegate:nsobject <UIApplicationDelegate>{iboutlet UIWindow*window;} @property (nonatomic, retain) UIWindow*window; @property (nonatomic, retain) Mypageviewcontroller*Viewcontroller, @property (nonatomic, retain) Uinavigationcontroller*nav;@end@implementationhelloworldappdelegate@synthesizewindow;@synthesizeViewcontroller;-(void) Applicationdidfinishlaunching: (UIApplication *) application{Self.window=[[UIWindow alloc] Initwithframe:[[uiscreen Mainscreen]bounds]]; Self.viewcontroller=[[Mypageviewcontroller alloc]init]; //Self.window.rootViewController = Self.viewcontroller;Self.nav=[[Uinavigationcontroller Alloc]initwithrootviewcontroller:viewcontroller];        [Self.nav Setnavigationbarhidden:yes]; //hide the navigation bar at the top of the view[Self.nav Settoolbarhidden:yes];//hide the toolbar at the bottom of the viewSelf.window.rootViewController=Self.nav; [Self.window makekeyandvisible];}@end//-----------------------------Program Entry-----------------------------intMainintargcChar*argv[]) {@autoreleasepool {returnUiapplicationmain (argc, argv, Nil,@"helloworldappdelegate"); }}

IOS: Page Flipping effect

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.