Add App first launch page

Source: Internet
Author: User

One, add several member variables

@interface Hdisplayview () <UIScrollViewDelegate>{    uiscrollview    *_bigscrollview;    Nsmutablearray  *_imagearray;    Uipagecontrol   *_pagecontrol;}

Second, add the construction method

-(Instancetype) initWithFrame: (cgrect) frame{ Self=[Super Initwithframe:frame]; if(self) {_imagearray= [@[@"splash Screen 1.png",@"splash screen 2.png",@"splash Screen 3.png",@"splash Screen 4.png"]mutablecopy]; //_imagearray = [Nsmutablearray arraywithobjects:@ "splash screen 1.png", @ "splash screen 2.png", @ "flash screen 3.png", @ "flash screen 4.png", nil];Uiscrollview*scrollview = [[Uiscrollview alloc]initwithframe:cgrectmake (0,0, Mainscreen_width, Mainscreen_height)]; Scrollview.contentsize= Cgsizemake ((_imagearray.count +1)*mainscreen_width, mainscreen_height); //set the anti-wild effect, do not allow bounce, do not display the horizontal slider, set the agent for their ownscrollview.pagingenabled = YES;//Set Page PagingScrollview.bounces =NO; Scrollview.showshorizontalscrollindicator=NO; ScrollView.Delegate=Self ;        [Self addsubview:scrollview]; _bigscrollview=ScrollView;  for(inti =0; i < _imagearray.count; i++) {Uiimageview*imageview =[[Uiimageview alloc]init]; Imageview.frame= CGRectMake (i * mainscreen_width,0, Mainscreen_width, mainscreen_height); UIImage*image =[UIImage Imagenamed:_imagearray[i]]; Imageview.image=image;        [ScrollView Addsubview:imageview]; } Uipagecontrol*pagecontrol = [[Uipagecontrol alloc]initwithframe:cgrectmake (mainscreen_width/2, Mainscreen_height- -,0, +)]; Pagecontrol.numberofpages=_imagearray.count; Pagecontrol.backgroundcolor=[Uicolor Clearcolor];                [Self Addsubview:pagecontrol]; _pagecontrol=Pagecontrol; //Add gesturesUITapGestureRecognizer *Singlerecognizer; Singlerecognizer=[[UITapGestureRecognizer alloc]initwithtarget:self Action: @selector (Handlesingletapfrom)]; Singlerecognizer.numberoftapsrequired=1;            [ScrollView Addgesturerecognizer:singlerecognizer]; }        returnSelf ;}

Three, add a gesture, in the thoughtful last page, let the whole view hidden

-(void) handlesingletapfrom{    if3) {                = YES;            }}

Four, add a ScrollView proxy method, let Pagecontrol in the middle position of ScrollView

-(void) scrollviewdidenddecelerating: (Uiscrollview *) scrollview{    if (ScrollView = = _bigscrollview) {                cgpoint OffSet = Scrollview.contentoffset;                _pagecontrol.currentpage = offset.x/(self.bounds.size.width);//Calculate the current page number        [ScrollView setcontentoffset: Cgpointmake (Self.bounds.size.width * (_pagecontrol.currentpage), Scrollview.contentoffset.y) Animated:yes];            }        if (Scrollview.contentoffset.x = = (_imagearray.count) *mainscreen_width) {                Self.hidden = YES;            }    }

Add App first launch page

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.