Use Uipagecontrol Uiscrollview to create an app boot interface

Source: Internet
Author: User

1. Create a new two view controller class (inherited from Uiviewcontroller) and specify the root view controller in the APPDELEGATE.M
#import "AppDelegate.h" #import "RootViewController.h" #import "LeadViewController.h" @interface appdelegate () @    End@implementation appdelegate-(void) dealloc{Self.window = nil; [Super Dealloc];}    -(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions {    Self.window = [[[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds]] autorelease];    Override point for customization after application launch.    Self.window.backgroundColor = [Uicolor Whitecolor];        [Self.window makekeyandvisible]; Mark the user's preferences to determine if the user is opening the application for the first time//[Nsuserdefaults standarduserdefaults];    Get user preferences options BOOL isFirst = [[Nsuserdefaults standarduserdefaults] boolforkey:@ "NB"]; NSLog (@ "IsFirst =%d", isFirst);  First print is 0, second print is 1 if (IsFirst) {//If true, go directly to application rootviewcontroller *ROOTVC = [[Rootviewcontroller alloc]        INIT];        Self.window.rootViewController = ROOTVC;            [ROOTVC release]; } else {//If False,Start the boot page leadviewcontroller *LEADVC = [[Leadviewcontroller alloc] init];        Self.window.rootViewController = LEADVC;            [LEADVC release]; } return YES;

 2. Write the main code in Leadviewcontroller

leadviewcontroller.m/** * * * */#import "LeadViewController.h" #import "RootViewController.h" #define kscreenwidth [UIScreen mainscreen].bounds.size.width#define kscreenheight [UIScreen mainScreen].bounds.size.height# Define Kimagecount 6@interface Leadviewcontroller () <UIScrollViewDelegate> @property (nonatomic, retain) Uipagecontrol *pagecontrol; @property (nonatomic, retain) Uiscrollview *scrollview; @end @implementation    leadviewcontroller-(void) dealloc{Self.pagecontrol = nil;    Self.scrollview = nil; [Super Dealloc];}    -(void) viewdidload {[Super viewdidload];        Self.view.backgroundColor = [Uicolor Redcolor];     [Self configurescrollview]; [Self Configurepagecontrol]; //! Call this method first, then the ScrollView will pagecontrol to cover the}//configuration scrolling View-(void) Configurescrollview {self.scrollview = [[UIS    Crollview alloc] Initwithframe:[uiscreen mainscreen].bounds];    _scrollview.backgroundcolor = [Uicolor Yellowcolor]; Content area Size _scrollview.contentsize =Cgsizemake (Kimagecount * kscreenwidth, kscreenheight);    Content area width is the number of pictures * screen width [self.view addsubview:_scrollview];        [_scrollview release]; Add ImageView object to _scrollview for (int i = 0; i < Kimagecount; i++) {//Prepare picture UIImage *image = [Uiimag        E imagenamed:[nsstring stringwithformat:@ "v6_guide_%d", i+1]];        Create Uiimageview object Uiimageview *imageview = [[Uiimageview alloc] initwithimage:image]; Set Frame Imageview.frame = CGRectMake (kscreenwidth * I, 0, kscreenwidth, kscreenheight);                //! //!        Let _scrollview full page slide _scrollview.pagingenabled = YES; //!                Close Spring effect _scrollview.bounces = NO; _scrollview.delegate = self;                Adding agents, handling events [_scrollview Addsubview:imageview];                [ImageView release]; The last picture adds a tap gesture if (5 = = i) {imageview.userinteractionenabled = YES;//! The default interaction for Uilabel and Uiimageview is off UitapgesturerecognIzer *tap = [[UITapGestureRecognizer alloc] initwithtarget:self action: @selector (Handletap:)];                    [ImageView addgesturerecognizer:tap];//gesture added to ImageView [tap release]; }}}//implement gesture associated event-(void) Handletap: (UITapGestureRecognizer *) Tap {//Set user preferences [[Nsuserdefaults Standarduserd    Efaults] Setbool:yes forkey:@ "NB"]; Change the root view of the application window controller//[uiapplication sharedapplication] Remove the current Application object Rootviewcontroller *ROOTVC = [[Rootviewcontroller        Alloc]init]; [UIApplication sharedapplication].keywindow.rootviewcontroller = ROOTVC;        The window in the window and APPDELEGATE.M is a window [ROOTVC release]; }//Configure paging Controller-(void) Configurepagecontrol {self.pagecontrol = [[Uipagecontrol alloc] initWithFrame: (CGRectMake (0, KScree    nHeight-40, Kscreenwidth, 30))];//add Pagecontro//_pagecontrol.backgroundcolor = [Uicolor blackcolor] below the screen;    Number of pages _pagecontrol.numberofpages = Kimagecount; The color of the current point _pagecontroL.currentpageindicatortintcolor = [Uicolor Greencolor];    Other points of color _pagecontrol.pageindicatortintcolor = [Uicolor Yellowcolor]; Add associated event [_pagecontrol addtarget:self Action: @selector (Handlepagecontrol:) forControlEvents: (    uicontroleventvaluechanged)];    Add to the View controller [Self.view Addsubview:_pagecontrol];    [_pagecontrol release]; } #pragma maek-Implement proxy method (method in protocol)-(void) scrollviewdidenddecelerating: (Uiscrollview *) ScrollView {//deceleration at end of offset cgpoin    T offSet = Scrollview.contentoffset;    CGFloat number = Offset.x/kscreenwidth; _pagecontrol.currentpage = (nsinteger) number;    Image associated with Point ScrollView and Pagecontrol Association}//implements the method associated with the paging controller-(void) Handlepagecontrol: (Uipagecontrol *) Sender {//Remove current paging    Nsinteger number = Sender.currentpage; The offset of the ScrollView is controlled by paging _scrollview.contentoffset = cgpointmake (number * kscreenwidth, 0);    The point associated with the image Pagecontrol with ScrollView}-(void) didreceivememorywarning {[Super didreceivememorywarning]; Dispose of any ResourCes that can be recreated.} @end

The combination of the two UI controls, Uipagecontrol and Uiscrollview, is common, and the first time the app is opened, the boot interface can be used with these two controls to complete the ~

Use Uipagecontrol Uiscrollview to create an app boot interface

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.