APP首次启动引导界面和启动界面设置——iOS开发

 
标签: iOS开发界面启动
 分类:
UI基础(19) 

APP下载安装第一次使用一般会显示一个首次启动引导界面然后进入主界面,非首次开启APP也通常会显示一个启动界面然后进入主界面。


1、本例首次启动显示FirstUseViewController,添加一个button,点击进入LaunchViewController 
2、非首次LaunchViewController,显示2s后进入主界面ViewController 
3、主界面ViewController 
4、不深究细节,一般启动引导都会有动画,图片之类的,非本次练习重点,所以没有设置,只有简单地标志作界面区分 
(效果图在文末)


FirstUseViewController.m


- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor greenColor]; UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; button.center = self.view.center; [button setTitle:@"Welcome" forState:UIControlStateNormal]; [button addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button]; } //点击button切换到下一个界面 - (void)btnAction:(UIButton *)btn { LaunchViewController *vc = [[LaunchViewController alloc] init]; self.view.window.rootViewController = vc; } 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

LaunchViewController.m

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor blueColor]; UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 50)]; label.center = self.view.center; [label setFont:[UIFont systemFontOfSize:30]]; label.text = @"启动页面"; [self.view addSubview:label]; // 延迟2s调用,一般启动页面会停留,或者有些动画什么的,本例只简述思路,不深究细节 [self performSelector:@selector(changeView) withObject:self afterDelay:2]; // Do any additional setup after loading the view. } //切换到下一个界面 - (void)changeView { UIWindow *window = self.view.window; ViewController *main = [[ViewController alloc] init]; //添加一个缩放效果 main.view.transform = CGAffineTransformMakeScale(0.2, 0.2); [UIView animateWithDuration:0.1 animations:^{ main.view.transform = CGAffineTransformIdentity; }]; window.rootViewController = main; } 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29

ViewController.m

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor grayColor];
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 50)];
    label.center = self.view.center;
    [label setFont:[UIFont systemFontOfSize:30]];
    label.text = @"主界面";
    [self.view addSubview:label];
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

AppDelegate.m设置,两种方法。个人觉得第二种利用NSUserDefaults实现更方便

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible];  利用文件操作判断是否为第一次使用此APP // NSString *filePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/firstUse.plist"]; //第一次启动,没有此文件,会自动创建 // NSDictionary *dic = [NSDictionary dictionaryWithContentsOfFile:filePath]; // // BOOL notFirstUse = YES; // notFirstUse = [dic[@"notFirstUse"] boolValue]; // if (!notFirstUse) { // NSDictionary *dic = @{@"notFirstUse" : @YES }; // [dic writeToFile:filePath atomically:YES]; // FirstUseViewController *vc = [[FirstUseViewController alloc] init]; // self.window.rootViewController = vc; // }else { // LaunchViewController *vc = [[LaunchViewController alloc] init]; // self.window.rootViewController = vc; // } // // 利用NSUserDefaults实现 if(![[NSUserDefaults standardUserDefaults] boolForKey:@"firstLaunch"]) { [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"firstLaunch"]; NSLog(@"首次启动"); FirstUseViewController *vc = [[FirstUseViewController alloc] init]; self.window.rootViewController = vc; }else { NSLog(@"非首次启动"); LaunchViewController *vc = [[LaunchViewController alloc] init]; self.window.rootViewController = vc; } return YES; } 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37

界面效果图: 
首次启动页面: 
首次启动页面


非首次启动页面: 
非首次启动页面


主界面: 
主界面

 

转载于:https://www.cnblogs.com/ios4app/p/6873571.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值