前几天见到一个比较有意思的一个东西。虽然没有什么技术难点,但感觉还是挺有意思的。就是在用户初次启动App时,会有一个引导页面。当用户第二次运行的时候就不会有了。
先说一下我个人的见解吧。这个其实是在用户运行App时,将是否运行过这个App的信息存储在userdefault中。当用户在运行一次后,userdefault中的key对应有值,走的if另个分支。下边看代码:
在AppDelegate中:
NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
NSString *isFirst = [user objectForKey:@"first"];//任意定义一个key,使得App第一次运行时没有值,走if中的else语句
if(isFirst){//不是第一次,只有一张图片引导
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
imageView.image = [UIImage imageNamed:@"Default"];
[self.window addSubview:imageView];
}else{//第一次,设置一个动画效果来引导用户
FirstRunViewController *first = [[FirstRunViewController alloc] init];
[user setObject:@"first" forKey:@"first"];
[user synchronize];
self.window.rootViewController = first;
}
NSArray *pictures = @[@"intro1",@"intro2",@"intro3",@"intro4",@"intro5"];//这是几张引导图片
UIScrollView *_scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
for(NSInteger i=0;i<pictures.count;i++)
{
UIImageView *iamgeView = [[UIImageView alloc] initWithFrame:CGRectMake(320*i, 0, 320, 480)];
iamgeView.image = [UIImage imageNamed:pictures[i]];
[_scrollView addSubview:iamgeView];
if(i==4){//最后一张添加点击手势
iamgeView.userInteractionEnabled = YES;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onTap)];
[iamgeView addGestureRecognizer:tap];
}
}
_scrollView.pagingEnabled = YES;
_scrollView.contentSize = CGSizeMake(320*pictures.count, 480);
[self.view addSubview:_scrollView];
- (void)onTap
{
RootViewController *root = [[RootViewController alloc] init];
[self presentViewController:root animated:YES completion:^{
}];
}