Introduction to guide page features
Mode one:
Determines whether a program starts for the first time, if it is the Guidepageviewcontroller as the root view controller for the window. Guidepageviewcontroller has three child controls: a Uiscrollview, a Uipagecontrol, a UIButton (hidden by default), Uiscrollview has multiple Uiimageview child controls, When scrolling to the last page UIButton show, click the immediate experience and then set the window's root view controller to Uitabbarcontroller;
Mode two:
You can also set the root view controller directly to Uitabbarcontroller, and then display the Boot Page view on the first navigation controller view, and then hide the boot Page view when you click the immediate experience.
Sample code
@implementation appdelegate
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: ( Nsdictionary *) launchoptions {
////////////////////////////////////
Self.window.rootViewController = [[Guidepageviewcontroller alloc] init];
Return YES
}
@end
Boot Page view Controller Guidepageviewcontroller
#import "GuidePageViewController.h" #import "ViewController.h" #define KSCREENWIDTH ([UIScreen mainscreen]. Bounds.size.width) #define Kscreenheight ([UIScreen mainscreen].bounds.size.height) #define KGUIDEPAGECOUNT 4 @ Interface Guidepageviewcontroller () <UIScrollViewDelegate> @property (weak, nonatomic) Uipagecontrol *
Pagecontrol;
@property (Weak, nonatomic) UIButton *startappbutton;
@end @implementation Guidepageviewcontroller-(void) viewdidload {[Super viewdidload]; Uiscrollview Uiscrollview *guidepagescrollview = [[Uiscrollview alloc] Initwithframe:cgrectmake (0, 0, KScreenWidth, K
ScreenHeight)];
Guidepagescrollview.contentsize = Cgsizemake (kscreenwidth * kguidepagecount, 0);
Guidepagescrollview.showshorizontalscrollindicator = NO;
guidepagescrollview.pagingenabled = YES;
Guidepagescrollview.bounces = NO;
Guidepagescrollview.delegate = self; for (int i = 0; i < Kguidepagecount i++) {Uiimageview *guideimageview = [[Uiimageview alloc] Initwithframe:cgrEctmake (kscreenwidth * I, 0, Kscreenwidth, kscreenheight)];
Guideimageview.image = [UIImage imagenamed:[nsstring stringwithformat:@ "guide-page-%d", I + 1]];
[Guidepagescrollview Addsubview:guideimageview];
} [Self.view Addsubview:guidepagescrollview]; Uipagecontrol (paging) Uipagecontrol *pagecontrol = [[Uipagecontrol alloc] Initwithframe:cgrectmake ((kScreenWidth-100)/
2, KSCREENHEIGHT-50, 100, 30)];
Pagecontrol.numberofpages = Kguidepagecount;
pagecontrol.currentpage = 0;
Pagecontrol.currentpageindicatortintcolor = [Uicolor Greencolor];
[Self.view Addsubview:pagecontrol];
Self.pagecontrol = Pagecontrol;
UIButton (experience immediately) UIButton *startappbutton = [UIButton buttonwithtype:uibuttontypecustom];
Startappbutton.frame = CGRectMake (kScreenWidth-100)/2, 550, 100, 40);
[Startappbutton settitle:@ "immediately experience" forstate:uicontrolstatenormal];
Startappbutton.backgroundcolor = [Uicolor Graycolor]; [Startappbutton addtarget:self Action: @selector (startappaction) forcontrolevents: UIControlEventTouchUpInside];
Startappbutton.hidden = YES;
[Self.view Addsubview:startappbutton];
_startappbutton = Startappbutton; }-(void) Scrollviewdidscroll: (Uiscrollview *) ScrollView {Nsinteger currentpage = Scrollview.contentoffset.x/kscreenw
Idth;
Self.pageControl.currentPage = CurrentPage;
if (currentpage = = (kGuidePageCount-1)) {Self.startAppButton.hidden = NO; }-(void) Startappaction {//root view controller is generally uitabbarcontroller, here is a simple implementation [UIApplication Sharedapplication].keywindow.rootvie
Wcontroller = [[Viewcontroller alloc] init];
} @end
The picture name in the above code is written dead in the Guidepageviewcontroller, the root View controller is also written dead, if other apps want to reuse this function, it is necessary to enter the code to modify these two areas, in order not to modify a line of code can use this function, These two parameters can be extracted and passed as parameters when the controller is initialized
Encapsulate Sample Code
Passes the picture and Root view controller to the Boot Page view controller as a parameter when initialized
@implementation appdelegate
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: ( Nsdictionary *) launchoptions {
Viewcontroller *viewcontroller = [[Viewcontroller alloc] init];
Self.window.rootViewController = [[Guidepageviewcontroller alloc] initwithimages:@[@ "guide-page-1", @ "Guide-page-2" , @ "guide-page-3", @ "guide-page-4"] rootviewcontroller:viewcontroller];
Return YES
}
@end
#import <UIKit/UIKit.h>
@interface guidepageviewcontroller:uiviewcontroller
-(instancetype) Initwithimages: (Nsarray *) images Rootviewcontroller: (Uiviewcontroller *) Rootviewcontroller;
@end
In the initialization method, save the boot page picture and the root view controller, use Self.images.count to get the number of boot pages, and the boot page picture is fetched directly from the images array
#import "GuidePageViewController.h" #import "ViewController.h" #define KSCREENWIDTH ([UIScreen mainscreen]. Bounds.size.width) #define Kscreenheight ([UIScreen mainscreen].bounds.size.height) @interface
Guidepageviewcontroller () <UIScrollViewDelegate> @property (weak, nonatomic) Uipagecontrol *pagecontrol;
@property (Weak, nonatomic) UIButton *startappbutton;
@property (Strong, nonatomic) Nsarray *images;
@property (Strong, nonatomic) Uiviewcontroller *rootviewcontroller; @end @implementation Guidepageviewcontroller-(Instancetype) Initwithimages: (Nsarray *) images Rootviewcontroller: (
Uiviewcontroller *) Rootviewcontroller {if (self = [super init]) {_images = images;
_rootviewcontroller = Rootviewcontroller;
return self;
}-(void) viewdidload {[Super viewdidload]; Uiscrollview Uiscrollview *guidepagescrollview = [[Uiscrollview alloc] Initwithframe:cgrectmake (0, 0, KScreenWidth, K
ScreenHeight)]; Guidepagescrollview.contentsize = Cgsizemake (Kscreenwidth *Self.images.count, 0);
Guidepagescrollview.showshorizontalscrollindicator = NO;
guidepagescrollview.pagingenabled = YES;
Guidepagescrollview.bounces = NO;
Guidepagescrollview.delegate = self; for (int i = 0; i < Self.images.count i++) {Uiimageview *guideimageview = [[Uiimageview alloc] Initwithframe:cgrect
Make (Kscreenwidth * I, 0, Kscreenwidth, kscreenheight)];
Guideimageview.image = [UIImage imagenamed:self.images[i]];
[Guidepagescrollview Addsubview:guideimageview];
} [Self.view Addsubview:guidepagescrollview]; Uipagecontrol Uipagecontrol *pagecontrol = [[Uipagecontrol alloc] Initwithframe:cgrectmake ((kScreenWidth-100)/2, K
SCREENHEIGHT-50, 100, 30)];
Pagecontrol.numberofpages = Self.images.count;
pagecontrol.currentpage = 0;
Pagecontrol.currentpageindicatortintcolor = [Uicolor Greencolor];
[Self.view Addsubview:pagecontrol];
Self.pagecontrol = Pagecontrol;
UIButton *startappbutton = [UIButton buttonwithtype:uibuttontypecustom]; Startappbutton.framE = CGRectMake ((kScreenWidth-100)/2, 550, 100, 40);
[Startappbutton settitle:@ "immediately experience" forstate:uicontrolstatenormal];
Startappbutton.backgroundcolor = [Uicolor Graycolor];
[Startappbutton addtarget:self Action: @selector (Startappaction) forcontrolevents:uicontroleventtouchupinside];
Startappbutton.hidden = YES;
[Self.view Addsubview:startappbutton];
_startappbutton = Startappbutton; }-(void) Scrollviewdidscroll: (Uiscrollview *) ScrollView {Nsinteger currentpage = Scrollview.contentoffset.x/kscreenw
Idth;
Self.pageControl.currentPage = CurrentPage;
if (currentpage = = (self.images.count-1)) {Self.startAppButton.hidden = NO;
}-(void) startappaction {[UIApplication sharedapplication].keywindow.rootviewcontroller = Self.rootviewcontroller;
} @end
Ultimate Solution
GitHub the boot page by using the Open Source feature on the GitHub directly
1. Create all the boot pages eaintropage
2, create the Guide page view Eaintroview and set up the agent
3. Display the Guide Page view
Create all the boot pages eaintropage
Basic: Title and description
eaintropage *page1 = [Eaintropage page];
Page1.title = @ "Hello World";
Page1.desc = SampleDescription1;
Custom
Eaintropage *page2 = [Eaintropage page];
Page2.title = @ "This is page 2";
Page2.titlefont = [Uifont fontwithname:@ "Georgia-bolditalic" size:20];
Page2.titlepositiony = A;
Page2.desc = SampleDescription2;
Page2.descfont = [Uifont fontwithname:@ "Georgia-italic" size:18];
Page2.descpositiony =;
Page2.titleiconview = [[Uiimageview alloc] initwithimage:[uiimage imagenamed:@ "Title2"]];
Page2.titleiconpositiony = m;
Custom View from nib
eaintropage *page3 = [eaintropage pagewithcustomviewfromnibnamed:@ "Intropage"];
Page3.bgimage = [UIImage imagenamed:@ "Bg2"];
Create a Guide Page view Eaintroview and set up a proxy
Eaintroview *intro = [[Eaintroview alloc] initWithFrame:self.view.bounds Andpages:@[page1,page2,page3,page4]];
intro.delegate=self;
Show Boot Page view
[Intro ShowInView:self.view animateduration:0.0];
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.