本文使用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在这,如有更好的方法可指出。