一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務(wù)器之家 - 編程語言 - IOS - iOS App引導(dǎo)頁開發(fā)教程

iOS App引導(dǎo)頁開發(fā)教程

2021-02-03 14:38u013147734 IOS

這篇文章主要為大家詳細(xì)介紹了iOS App引導(dǎo)頁開發(fā)教程,具有一定的參考價值,感興趣的小伙伴們可以參考一下

引導(dǎo)頁功能簡介

方式一:
判斷程序是否首次啟動,如果是將guidepageviewcontroller作為窗口的根視圖控制器。guidepageviewcontroller有三個子控件:一個uiscrollview、一個uipagecontrol、一個uibutton(默認(rèn)隱藏),uiscrollview有多個uiimageview子控件,當(dāng)滾動到最后一頁uibutton展示,點擊立即體驗然后將窗口的根視圖控制器設(shè)置為uitabbarcontroller;

方式二:
也可以直接將根視圖控制器設(shè)置為uitabbarcontroller, 然后在第一個導(dǎo)航控制器的視圖上展示引導(dǎo)頁視圖,當(dāng)點擊立即體驗再將引導(dǎo)頁視圖隱藏掉即可。

示例代碼

?
1
2
3
4
5
6
7
8
@implementation appdelegate
 
- (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions {
 // 首次啟動應(yīng)用程序時進(jìn)入到引導(dǎo)頁頁面(暫時沒有判斷,可通過nsuserdefault實現(xiàn))
 self.window.rootviewcontroller = [[guidepageviewcontroller alloc] init];
 return yes;
}
@end

引導(dǎo)頁視圖控制器guidepageviewcontroller

 

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#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, kscreenheight)];
 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(分頁)
 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(立即體驗)
 uibutton *startappbutton = [uibutton buttonwithtype:uibuttontypecustom];
 startappbutton.frame = cgrectmake((kscreenwidth - 100) / 2, 550, 100, 40);
 [startappbutton settitle:@"立即體驗" 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 / kscreenwidth;
 self.pagecontrol.currentpage = currentpage;
 if (currentpage == (kguidepagecount - 1)) {
  self.startappbutton.hidden = no;
 }
}
 
- (void)startappaction {
 // 根視圖控制器一般是uitabbarcontroller,這里簡單實現(xiàn)
 [uiapplication sharedapplication].keywindow.rootviewcontroller = [[viewcontroller alloc] init];
}
@end

上述代碼中的圖片名稱是寫死在guidepageviewcontroller中的,根視圖控制器也是寫死的,如果其他app想要復(fù)用該功能,就要進(jìn)入該代碼修改這兩哥地方,為了不修改一行代碼就可以使用該功能,可以將這兩個參數(shù)提取出來,初始化該控制器時作為參數(shù)傳遞

封裝示例代碼

初始化時以參數(shù)的形式將圖片和根視圖控制器傳遞給引導(dǎo)頁視圖控制器

?
1
2
3
4
5
6
7
@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
?
1
2
3
4
5
6
#import <uikit/uikit.h>
@interface guidepageviewcontroller : uiviewcontroller
 
- (instancetype)initwithimages:(nsarray *)images rootviewcontroller:(uiviewcontroller *)rootviewcontroller;
 
@end

在初始化方法中將引導(dǎo)頁圖片和根視圖控制器保存起來,使用self.images.count獲取引導(dǎo)頁數(shù)量,引導(dǎo)頁圖片直接從images數(shù)組中獲取

 

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#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, kscreenheight)];
 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:cgrectmake(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, kscreenheight- 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:@"立即體驗" 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 / kscreenwidth;
 self.pagecontrol.currentpage = currentpage;
 if (currentpage == (self.images.count - 1)) {
  self.startappbutton.hidden = no;
 }
}
 
 
- (void)startappaction {
 [uiapplication sharedapplication].keywindow.rootviewcontroller = self.rootviewcontroller;
}
@end

終極解決方案

直接使用github上的開源功能即可github引導(dǎo)頁

1、創(chuàng)建出所有引導(dǎo)頁eaintropage
2、創(chuàng)建引導(dǎo)頁視圖eaintroview 并設(shè)置代理
3、顯示引導(dǎo)頁視圖

創(chuàng)建出所有引導(dǎo)頁eaintropage

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// basic: 標(biāo)題和描述
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 = 220;
page2.desc = sampledescription2;
page2.descfont = [uifont fontwithname:@"georgia-italic" size:18];
page2.descpositiony = 200;
page2.titleiconview = [[uiimageview alloc] initwithimage:[uiimage imagenamed:@"title2"]];
page2.titleiconpositiony = 100;
 
// custom view from nib
eaintropage *page3 = [eaintropage pagewithcustomviewfromnibnamed:@"intropage"];
page3.bgimage = [uiimage imagenamed:@"bg2"];

創(chuàng)建引導(dǎo)頁視圖eaintroview 并設(shè)置代理
eaintroview *intro = [[eaintroview alloc] initwithframe:self.view.bounds andpages:@[page1,page2,page3,page4]];
intro.delegate=self;

顯示引導(dǎo)頁視圖
[intro showinview:self.view animateduration:0.0];

iOS App引導(dǎo)頁開發(fā)教程

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持服務(wù)器之家。

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 国产福利一区二区精品视频 | 亚洲欧美日韩中文字幕网址 | 久久毛片基地 | 好大好爽好硬我要喷水了 | 国产欧美亚洲精品第一页青草 | 免费看国产一级片 | 免费稚嫩福利 | 美女模特被c免费视频 | 欧美一级视频在线观看 | 欧美一区二区三区精品影视 | 国产在线视频色综合 | 亚洲精品一二三四 | 香蕉国产成版人视频在线观看 | 大陆日韩欧美 | 99久久久久国产精品免费 | 亚洲国产福利精品一区二区 | 精品蜜臀AV在线天堂 | 精品免费tv久久久久久久 | 69罗莉视频在线观看 | 亚洲精品成人AV在线观看爽翻 | 男插女的下面免费视频夜色 | 毛片免费全部免费观看 | 青青热久麻豆精品视频在线观看 | 国产一区视频在线免费观看 | 欧美综合影院 | 日韩视频免费一区二区三区 | 韩国美女被的免费视频 | 欧美视频在线播放观看免费福利资源 | 欧美激情精品久久久久久不卡 | 日韩欧美国产综合精品 | 午夜一区二区免费视频 | www.色婷婷.com| 福利片成人午夜在线 | 97se亚洲国产综合自在线观看 | 欧美国产日产精品免费视频 | 国产精品一久久香蕉产线看 | 99re5在线精品视频热线 | 久久亚洲精品AV成人无 | 精品综合久久久久久97超人 | 亚洲精品黄色 | 欧美日韩一本 |