一芒帕、App引導頁
一款App在首次安裝后打開時,會有3-5頁的介紹界面引導新用戶使用或者給用戶更新提示丰介。
根據(jù)引導頁的目的背蟆、出發(fā)點不同鉴分,可以將其分為功能介紹類、使用說明類带膀、推廣類志珍、問題解決類,一般引導頁不會超過5頁垛叨。 功能介紹類 功能介紹類引導頁主要是對產(chǎn)品的主要功能進行展示伦糯,讓用戶對產(chǎn)品主功能有一個大致的了解。
二嗽元、具體實現(xiàn)
1敛纲、本Demo是在繼承UICollectionViewController的前提下完成。
2剂癌、實現(xiàn)瀑布流
- (instancetype)init
{
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
// 設(shè)置cell的尺寸
layout.itemSize = [UIScreen mainScreen].bounds.size;
// 清空行距
layout.minimumLineSpacing = 0;
// 設(shè)置滾動的方向
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
return [super initWithCollectionViewLayout:layout];
}
3淤翔、實現(xiàn)collectionView布局
//使用UICollectionViewController
//1.初始化的時候設(shè)置布局參數(shù)
//2.必須collectionView要注冊cell
// 3.自定義cell
- (void)viewDidLoad {
[super viewDidLoad];
// 注冊cell,默認就會創(chuàng)建這個類型的cell
[self.collectionView registerClass:[ZJNewFeatureCell class] forCellWithReuseIdentifier:reuseIdentifier];
// 分頁
self.collectionView.pagingEnabled = YES;
self.collectionView.bounces = NO;
self.collectionView.showsHorizontalScrollIndicator = NO;
}
3、有關(guān)代理方法的實現(xiàn)
mark - UICollectionView代理和數(shù)據(jù)源
// 返回有多少組
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
// 返回第section組有多少個cell
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return 4;
}
// 返回cell長什么樣子
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
ZJNewFeatureCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
NSString *imageName = [_picStrArr objectAtIndex:indexPath.row];
cell.image = [UIImage imageNamed:imageName];
[cell setIndexPath:indexPath count:[_picStrArr count]];
return cell;
}
注:代用中使用的宏是寫在PCH文件中佩谷,PCH文件的配置見另一篇文章有關(guān)PCH文件的設(shè)置旁壮。
4、實現(xiàn)UICollectionViewCell
懶加載最后一張引導頁的點擊按鈕
- (UIButton *)startButton
{
if (_startButton == nil) {
UIButton *startBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[startBtn setBackgroundColor:[UIColor clearColor]];
[startBtn setBackgroundImage:[UIImage imageNamed:@"開啟按鈕"] forState:UIControlStateNormal];
[startBtn addTarget:self action:@selector(start) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:startBtn];
_startButton = startBtn;
}
return _startButton;
}
5谐檀、布局ZJNewFeatureCell子控件的frame
- (UIImageView *)imageView
{
if (_imageView == nil) {
UIImageView *imageV = [[UIImageView alloc] init];
_imageView = imageV;
// 注意:一定要加在contentView上
[self.contentView addSubview:imageV];
}
return _imageView;
}
// 布局子控件的frame
- (void)layoutSubviews
{
[super layoutSubviews];
self.imageView.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight);
[self.startButton setFrame:CGRectMake(0, 0, 170, 40)];
self.startButton.center = CGPointMake(ScreenWidth * 0.5, ScreenHeight -90);
}
6抡谐、開始按鈕的點擊事件,切換根視圖
- (void)start
{
//切換根視圖
self.window.rootViewController = [ViewController new];
//記錄是否已經(jīng)走過新特性
[[NSUserDefaults standardUserDefaults]setBool:YES forKey:[NSString stringWithFormat:@"ISNEWFEATURE%@",App_Version]];
[[NSUserDefaults standardUserDefaults]synchronize];
}
7桐猬、deledate中判斷是否展示引導頁
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor clearColor];
self.window.rootViewController = [[ViewController alloc]init];
NSArray *picStrArr = [NSArray arrayWithObjects:@"1242x2208_01",@"1242x2208_02", @"1242x2208_03", @"1242x2208_04", nil];
[NewFeatureManager shareManagerWithDelegate:self picStrArr:picStrArr];
return YES;
}
保存值的時候帶著版本號麦撵,是讓版本升級后首次打開也能展示引導頁。
demo地址下載:https://github.com/zhengju/GuidePageDemo