iOS引导页实现

本文使用UIScrollView与UIPageControl来实现引导页 

 

1、实现思路

        简述一下我的实现思路,图中引导页由3张图片构成,但实质上有四页。前三页中,每一页放入imageView,待操作翻到最后一页scrollView停止加速后切换根控制器(self.window.rootViewController)进入到mainViewController。

/* 已经停止加速 */
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    self.pageControl.currentPage = self.scrollView.contentOffset.x / kWidth;
    if (self.scrollView.contentOffset.x / kWidth == 3) {
        if (self.toNextVC) {
            self.toNextVC();
        }
    }
}

        [self readData],readData函数读取沙盒中的文件判断该APP是否为第一次启动,如若不是展示启动页。

MainViewController *mainVC = [MainViewController new];
    ViewController *vc = [ViewController new];
    if ([self readData]) {
        self.window.rootViewController = mainVC;
    } else {
        self.window.rootViewController = vc;
        vc.block = ^{
            NSLog(@"修改根控制器");
            self.window.rootViewController = mainVC;
        };
    }

2、判断是否为第一次启动

- (BOOL)readData {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *path = [paths objectAtIndex:0];
    NSString *filename = [path stringByAppendingPathComponent:@"created.plist"];   //获取路径
    
    NSDictionary* dic = [NSDictionary dictionaryWithContentsOfFile:filename];  //读取数据
    NSLog(@"dic is:%@",dic);
    
    //创建一个dic,写到plist文件里
    if (!dic) {
        NSDictionary* newDic = [NSDictionary new];
        newDic = [NSDictionary dictionaryWithObject:@"isCreated" forKey:@"created"];
        [newDic writeToFile:filename atomically:YES];
        return NO;
    } else {
        return YES;
    }
}

具体代码demo在这,如有更好的方法可指出。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值