iOS开发之引导页的实现

一、App引导页
一款App在首次安装后打开时,会有3-5页的介绍界面引导新用户使用或者给用户更新提示。
根据引导页的目的、出发点不同,可以将其分为功能介绍类、使用说明类、推广类、问题解决类,一般引导页不会超过5页。 功能介绍类 功能介绍类引导页主要是对产品的主要功能进行展示,让用户对产品主功能有一个大致的了解。
二、具体实现
1、本Demo是在继承UICollectionViewController的前提下完成。
2、实现瀑布流
- (instancetype)init
{
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];

// 设置cell的尺寸
layout.itemSize = [UIScreen mainScreen].bounds.size;
// 清空行距
layout.minimumLineSpacing = 0;

// 设置滚动的方向
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;

return [super initWithCollectionViewLayout:layout];

}

3、实现collectionView布局

 //使用UICollectionViewController
//1.初始化的时候设置布局参数
//2.必须collectionView要注册cell
// 3.自定义cell
- (void)viewDidLoad {
   [super viewDidLoad];
// 注册cell,默认就会创建这个类型的cell
[self.collectionView registerClass:[ZJNewFeatureCell class] forCellWithReuseIdentifier:reuseIdentifier];

// 分页
self.collectionView.pagingEnabled = YES;
self.collectionView.bounces = NO;
self.collectionView.showsHorizontalScrollIndicator = NO;

}

3、有关代理方法的实现

      mark - UICollectionView代理和数据源
 // 返回有多少组
- (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文件的配置见另一篇文章有关PCH文件的设置
4、实现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];

//记录是否已经走过新特性
[[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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 179,045评论 25 709
  • 钱人人都有,但人人都不一定能称得上是有钱人。有钱的人应该是买得起一线城市的房,开得了宝马路虎一类的豪车,用得上国际...
    性感有才的郭郭阅读 464评论 0 4
  • 亲爱的Wendy: 今天放学回家的时候,你超级开心。 原因有两: 1、你英语期中考试得了满分,老师奖励你一颗棒棒糖...
    C呀么CJ阅读 151评论 0 0
  • 今天做的发卷很好。面发的不错,很松软,可能是小麦粉的缘故,不够白,但是麦香味浓。比以前改进的地方是排气足,开蒸前二...
    何丽珍阅读 285评论 0 0
  • 文章作者:Tyan博客:noahsnail.com | CSDN | 简书 本文主要是关于numpy的一些基本运算...
    SnailTyan阅读 619评论 0 0

友情链接更多精彩内容