#import"RootViewController.h"#import"SecondViewController.h"#defineKscreenwidth [UIScreen mainscreen].bounds.size.width#definekscreenheight [UIScreen mainscreen].bounds.size.height#defineKimagecount 6#defineKimagename @ "V6_guide_"@interface Rootviewcontroller ()<UIScrollViewDelegate>@end @implementation Rootviewcontroller- (void) viewdidload {[Super viewdidload]; //Do any additional setup after loading the view.[self Layoutsubview];}- (void) didreceivememorywarning {[Super didreceivememorywarning]; //Dispose of any resources the can be recreated.}//Layout View- (void) layoutsubview{[self layoutscrollview]; [Self Layoutpagecontrol];}//Layout Uiscrollview- (void) layoutscrollview{//1. Create an ObjectUiscrollview *scrollview =[[Uiscrollview alloc] Initwithframe:[uiscreen mainscreen].bounds]; //2. Configuration PropertiesScrollview.contentsize = Cgsizemake (Kscreenwidth *Kimagecount, kscreenheight); //turn off the horizontal indicator, which is the horizontal scroll barScrollview.showshorizontalscrollindicator =NO; //set ScrollView whether the whole screen slidescrollview.pagingenabled =YES; //Set up proxyScrollView.Delegate= self;//At this point, the purpose of setting up the agent, in the protocol deceleration method, let ScrollView and Pagecontrol to establish contactScrollview.tag= $; //3. Add to Parent View[Self.view Addsubview:scrollview]; //4. Release[ScrollView release]; //Create Uiimageview for(inti =0; i < Kimagecount; i++) {Uiimageview*imageview = [[Uiimageview alloc] Initwithframe:cgrectmake (kscreenwidth * I,0, Kscreenwidth, Kscreenheight)]; Imageview.image= [UIImage imagenamed:[nsstring stringWithFormat:@"%@%d", Kimagename, i +1]]; [ScrollView Addsubview:imageview]; [ImageView release]; //determine if this is the last picture if(Kimagecount-1==i) {//if it is the last imageview to add a tap gesture, in order to enter the main interface of the programUITapGestureRecognizer *tapgesture =[[UITapGestureRecognizer alloc] initwithtarget:self action: @selector (handletapgesture:)]; //Add to view[ImageView addgesturerecognizer:tapgesture]; //Release[Tapgesture release]; //to open ImageView user interactionimageview.userinteractionenabled =YES; } } }//Layout Uipagecontrol- (void) layoutpagecontrol{Uipagecontrol*pagecontrol = [[Uipagecontrol alloc] Initwithframe:cgrectmake ( -, Kscreenheight- -*2, Kscreenwidth- -*2, -)]; Pagecontrol.numberofpages=Kimagecount; Pagecontrol.currentpageindicatortintcolor=[Uicolor Blackcolor]; Pagecontrol.tag= -; Pagecontrol.pageindicatortintcolor=[Uicolor Graycolor]; //Add Response Events[Pagecontrol addtarget:self Action: @selector (Handlepagecontrol:) forcontrolevents:uicontroleventvaluechanged] ; [Self.view Addsubview:pagecontrol]; [Pagecontrol release];}- (void) Handlepagecontrol: (Uipagecontrol *) pagecontrol{//1. Get to ScrollViewUiscrollview *SCROLLVW = (Uiscrollview *) [Self.view Viewwithtag: $]; //2. Modify the ScrollView offset[Scrollvw Setcontentoffset:cgpointmake (Kscreenwidth *pagecontrol.currentpage,0) Animated:yes];}#pragmamark-uiscrollviewdelegate-(void) Scrollviewdidenddecelerating: (Uiscrollview *) scrollview{//1. Get PagecontrolUipagecontrol *pagect = (Uipagecontrol *) [Self.view Viewwithtag: -]; //2. Set the Pagecontrol index, the current point purpose to let the point move with the diagramPagect.currentpage = scrollview.contentoffset.x/Kscreenwidth; }#pragmaPat Gesture-(void) Handletapgesture: (UITapGestureRecognizer *) tap{//Enter the program interfaceSecondviewcontroller *secondviewcontroller =[[Secondviewcontroller alloc] init]; //specify SECONDVC as the root view of window[UIApplication Sharedapplication].keywindow.rootviewcontroller =Secondviewcontroller; //Release[Secondviewcontroller release];} @end
Determine whether to log in for the first time
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions {Self.window=[[[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds]] autorelease]; //Override point for customization after application launch. //user index entries, store user information, whether the program is first started, and save user passwords.Nsuserdefaults *userdefalts =[Nsuserdefaults Standarduserdefaults]; if(! [Userdefalts Boolforkey:@"Firstlanch"]) { //Place markers Locally, next judgment, filter branches[Userdefalts setbool:yes Forkey:@"Firstlanch"]; //Sync now[Userdefalts Synchronize]; Rootviewcontroller*rootview =[[Rootviewcontroller alloc] init]; Self.window.rootViewController=Rootview; [Rootview release]; }Else{Secondviewcontroller*SECONDVC =[[Secondviewcontroller alloc] init]; Self.window.rootViewController=SECONDVC; [SECONDVC release]; } Self.window.backgroundColor=[Uicolor Whitecolor]; [Self.window makekeyandvisible]; returnYES;}
View after the boot interface ends
@implementation Secondviewcontroller- (void) viewdidload {[Super viewdidload]; Uiimageview*imgeview = [[Uiimageview alloc] Initwithframe:cgrectmake ( +, -, [UIScreen mainscreen].bounds.size.width- +*2, [UIScreen mainscreen].bounds.size.height- -*2)]; Imgeview.image= [UIImage imagenamed:@"1.jpg"]; [Self.view Addsubview:imgeview]; [Imgeview release];}- (void) didreceivememorywarning {[Super didreceivememorywarning]; //Dispose of any resources the can be recreated.}
ScrollView in iOS (scrolling, boot screen, and sentencing is the first time)