经常会在主 VC 前某些时候先显示其它的过渡页面,这个时候就要切换根视图
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
BOOL isFirstStart = YES;
self.window.backgroundColor = [UIColor whiteColor];
if(isFirstStart){
self.window.rootViewController = [AlertViewController new];
}else{
[self swtchToDefaultRootViewController];
}
[self.window makeKeyAndVisible];
return YES;
}
-(void)swtchToDefaultRootViewController{
[self.window.rootViewController.view removeFromSuperview];
self.window.rootViewController = [ViewController new];
}
第一个 VC
//
// AlertViewController.m
// mjtable
//
// Created by ldhonline on 2018/10/26.
// Copyright © 2018年 aidoutu.com. All rights reserved.
//
#import "AlertViewController.h"
#import "masonry.h"
#import "AppDelegate.h"
@interface AlertViewController ()
@end
@implementation AlertViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor lightGrayColor];
UIButton *btn = [[UIButton alloc] init];
[self.view addSubview:btn];
[btn mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.mas_equalTo(self.view);
make.width.mas_equalTo(200);
make.height.mas_equalTo(40);
}];
btn.backgroundColor = [UIColor grayColor];
[btn setTitle:@"关闭" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(dimss) forControlEvents:UIControlEventTouchUpInside];
}
- (void)dimss{
AppDelegate *currentAppDelegate = (AppDelegate *)([UIApplication sharedApplication].delegate);
[currentAppDelegate swtchToDefaultRootViewController];
}
@end
网友评论