Material Address http://download.csdn.net/download/swanzhu/9002215
zyappdelegate.m//scrollview_page////Created by Mac on 15-8-13.//Copyright (c) 2015 Baidu. All rights reserved.//#import "ZYAppDelegate.h" @implementation zyappdelegate-(BOOL) Application: (UIApplication *) Application didfinishlaunchingwithoptions: (nsdictionary *) launchoptions{Self.window = [[UIWindow alloc] Initwithframe:[[uiscreen Mainscreen] bounds]; Override point for customization after application launch. Self.window.backgroundColor = [Uicolor Whitecolor]; Slide View Scrollview=[[uiscrollview alloc] Initwithframe:cgrectmake (0, 10, 320, 200)]; for (int i=0; i<3; i++) {uiimageview *imageview=[[uiimageview alloc] Initwithframe:cgrectmake (320*i, 0, 320, 20 0)]; NSString *imgname=[nsstring stringwithformat:@ "%d.jpg", i+1]; Imageview.image=[uiimage Imagenamed:imgname]; [ScrollView Addsubview:imageview]; } scrollview.contentsize=cgsizemake (320*3, 200); Scrollview.pagingenabled=yes; [Self.window Addsubview:scrollview]; Set proxy scrollview.delegate=self; Pagecontrol Pagecontrol=[[uipagecontrol Alloc] Initwithframe:cgrectmake (100, 180, 120, 40)]; pagecontrol.numberofpages=3; [Self.window Addsubview:pagecontrol]; [Pagecontrol addtarget:self Action: @selector (ChangeValue) forcontrolevents:uicontroleventvaluechanged]; [Self.window makekeyandvisible]; [Nstimer scheduledtimerwithtimeinterval:1 target:self selector: @selector (OnTimer) Userinfo:nil Repeats:yes]; return YES;} -(void) ontimer{static int count=320; [ScrollView setcontentoffset:cgpointmake (scrollview.contentoffset.x+count, 0) Animated:yes]; if (scrollview.contentoffset.x==320) {count=-count; }}-(void) changevalue{//scrollview.contentoffset.x=pagecontrol.currentpage*320;//scrollview.contentof Fset=cgpointmake (pagecontrol.currentpage*320, 0); [ScrollView Setcontentoffset:cgpointmake (pagecontrol.currentpage*320, 0) animated:yes];} Method called after end deceleration-(void) scrollviewdidenddecelerating: (Uiscrollview *) scrollview{pagecontrol.currentpage = scrollview.contentoffset.x/320;} -(void) Applicationwillresignactive: (uiapplication *) application{//Sent when the application was about to move from AC tive to inactive state. This can occur for certain types of temporary interruptions (such as a incoming phone call or SMS message) or when the US Er quits the application and it begins the transition to the background state. Use the This method to the pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should with this method to pause the game.} -(void) Applicationdidenterbackground: (uiapplication *) application{//Use the method to release shared resources, SAV E user data, invalidate timers, and store enough application state information to restore your application State-in-case it is terminated later. //If your application supports background execution, this method was called instead of Applicationwillterminate:when the use R quits.} -(void) Applicationwillenterforeground: (uiapplication *) application{//called as part of the transition from the BACKG Round to the inactive State; Here's can undo many of the changes made on entering the background.} -(void) Applicationdidbecomeactive: (uiapplication *) application{//Restart Any tasks this were paused (or not yet star Ted) While the application was inactive. If the application is previously in the background, optionally refresh the user interface.} -(void) Applicationwillterminate: (uiapplication *) application{//Called when the application was about to terminate. Save data if appropriate. See also Applicationdidenterbackground:.} @end
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Swanzhu learning iOS (iv) Uiscrollview and Uipagecontrol