美文网首页
使用纯代码或者StoryBoard的时候加入用户引导页面

使用纯代码或者StoryBoard的时候加入用户引导页面

作者: 没脾气的淘气猫 | 来源:发表于2017-10-19 14:40 被阅读9次

如果想让一个APP加上引导页面是一个非常完美的举动

但是,总会遇到一些问题

(不要忘记在APDelegate里面加上用户引导页面的头文件和程序启动时的第一个页面哦)

情况一:纯代码

判断是否是第一次启动应用程序

- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions

{

self.window= [[UIWindowalloc]initWithFrame:[[UIScreenmainScreen]bounds]] ;

if(![[NSUserDefaultsstandardUserDefaults]boolForKey:@"firstLaunch"])

{

[[NSUserDefaultsstandardUserDefaults]setBool:YESforKey:@"firstLaunch"];

NSLog(@"第一次启动");

//如果是第一次启动的话,使用UserGuideViewController (用户引导页面)作为根视图

UserGuideViewController*userGuideViewController = [[UserGuideViewControlleralloc]init];

self.window.rootViewController= userGuideViewController;

}

else

{

NSLog(@"不是第一次启动");

TranslateController*tranVC = [[TranslateControlleralloc]init];

self.window.rootViewController= tranVC;

}

self.window.backgroundColor= [UIColorwhiteColor];

[self.windowmakeKeyAndVisible];

returnYES;

}

情况二:使用storyboard

情况基本相同,不同的是

NSLog(@"不是第一次启动");

UIStoryboard*story = [UIStoryboardstoryboardWithName:@"MainStoryboard"bundle:nil];

UIViewController* vc = [storyinstantiateViewControllerWithIdentifier:@"TranslateController"];

self.window.rootViewController= vc;

解释一下原理先,如果使用纯代码的话,不是第一次启动应用程序的时候会自动执行下面的代码,所以不会有问题

如果使用storyboard的话,初始化第一个视图控制器(程序第一个界面),什么都没有,(除非你自己使用代码添加控件),而且storyboard在启动的时候并不是从这里开始的,而是默认storyboard的第一个视图控制器,所以,加上一个标志就好

这样它就能找到应该启动的界面

相关文章

网友评论

      本文标题:使用纯代码或者StoryBoard的时候加入用户引导页面

      本文链接:https://www.haomeiwen.com/subject/cybuuxtx.html