在你的AppDelegage.m里面的 application: didFinishLaunchingWithOptions: 方法里面判断
首先引入两个类的头文件
- #import "LoginViewController.h"//应用首页
- #import "UserGuideViewController.h"//用户指导页面
|
然后进行判断
- //判断是不是第一次启动应用
- if(![[NSUserDefaults standardUserDefaults] boolForKey:@"firstLaunch"])
- {
- [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"firstLaunch"];
-
- NSLog(@"第一次启动");
-
- //如果是第一次启动的话,使用UserGuideViewController (用户引导页面) 作为根视图
-
- UserGuideViewController *userGuideViewController = [[UserGuideViewController alloc] init];
- self.window.rootViewController = userGuideViewController;
- [userGuideViewController release];
- }
- else{
- NSLog(@"已经不是第一次启动了");
-
- //如果不是第一次启动的话,使用LoginViewController作为根视图
-
- LoginViewController *loginViewController = [[LoginViewController alloc] init];
- self.window.rootViewController = loginViewController;
- [loginViewController release];
- }
|
另外也可以加上应用介绍相关的页面。
- UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 640)];
- [scrollView setContentSize:CGSizeMake(1280, 0)];
- [scrollView setPagingEnabled:YES]; //视图整页显示
- // [scrollView setBounces:NO]; //避免弹跳效果,避免把根视图露出来
-
- UIImageView *imageview = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
- [imageview setImage:[UIImage imageNamed:@"0.png"]];
- [scrollView addSubview:imageview];
- [imageview release];
-
- UIImageView *imageview1 = [[UIImageView alloc] initWithFrame:CGRectMake(320, 0, 320, 460)];
- [imageview1 setImage:[UIImage imageNamed:@"1.png"]];
- [scrollView addSubview:imageview1];
- [imageview1 release];
-
- UIImageView *imageview2 = [[UIImageView alloc] initWithFrame:CGRectMake(640, 0, 320, 460)];
- [imageview2 setImage:[UIImage imageNamed:@"2.png"]];
- [scrollView addSubview:imageview2];
- [imageview2 release];
-
- UIImageView *imageview3 = [[UIImageView alloc] initWithFrame:CGRectMake(960, 0, 320, 460)];
- [imageview3 setImage:[UIImage imageNamed:@"3.png"]];
- imageview3.userInteractionEnabled = YES; //打开imageview3的用户交互;否则下面的button无法响应
- [scrollView addSubview:imageview3];
- [imageview3 release];
-
- UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];//在imageview3上加载一个透明的button
- [button setTitle:nil forState:UIControlStateNormal];
- [button setFrame:CGRectMake(46, 371, 230, 37)];
- [button addTarget:self action:@selector(firstpressed) forControlEvents:UIControlEventTouchUpInside];
- [imageview3 addSubview:button];
-
- [self.view addSubview:scrollView];
- [scrollView setDelegate:self];
- [scrollView release];
|
点击button就进入应用了。
上面两个方法结合使用是现在大多数应用首次启动页用户指南的方式。