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