引导页
2015-07-22 13:26
381 查看
AppDelegate动态加载StoryBoard
2013-01-22 17:47 2287人阅读 评论(0) 收藏 举报
(BOOL)application:(UIApplication )application didFinishLaunchingWithOptions:(NSDictionary)launchOptions
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@”MainStoryboard” bundle:[NSBundlemainBundle]];
}
这是加载stortboard的做法
这是初始化引导页的方法
下面是俺的做法
2013-01-22 17:47 2287人阅读 评论(0) 收藏 举报
(BOOL)application:(UIApplication )application didFinishLaunchingWithOptions:(NSDictionary)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@”MainStoryboard” bundle:[NSBundlemainBundle]];
self.window.rootViewController=[storyboard instantiateInitialViewController]; [self.window makeKeyAndVisible]; return YES;
}
AppDelegate动态加载StoryBoard
2013-01-22 17:47 2287人阅读 评论(0) 收藏 举报
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundlemainBundle]];
self.window.rootViewController=[storyboard instantiateInitialViewController]; [self.window makeKeyAndVisible]; return YES;
}
这是加载stortboard的做法
这个功能的重点就是在如何判断应用是第一次启动的. 其实很简单 我们只需要在一个类里面写好用户引导页面 基本上都是使用UIScrollView 来实现, 新建一个继承于UIViewController的类 命名为 UserGuideViewController , 在UserGuideViewController.m 写 1 - (void)viewDidLoad 2 { 3 [super viewDidLoad]; 4 // Do any additional setup after loading the view. 5 self.view.backgroundColor = [UIColor redColor]; 6 7 [self initGuide]; //加载新用户指导页面 8 } 9 10 - (void)initGuide 11 { 12 UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 640)]; 13 [scrollView setContentSize:CGSizeMake(1280, 0)]; 14 [scrollView setPagingEnabled:YES]; //视图整页显示 15 // [scrollView setBounces:NO]; //避免弹跳效果,避免把根视图露出来 16 17 UIImageView *imageview = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)]; 18 [imageview setImage:[UIImage imageNamed:@"0.png"]]; 19 [scrollView addSubview:imageview]; 20 [imageview release]; 21 22 UIImageView *imageview1 = [[UIImageView alloc] initWithFrame:CGRectMake(320, 0, 320, 460)]; 23 [imageview1 setImage:[UIImage imageNamed:@"1.png"]]; 24 [scrollView addSubview:imageview1]; 25 [imageview1 release]; 26 27 UIImageView *imageview2 = [[UIImageView alloc] initWithFrame:CGRectMake(640, 0, 320, 460)]; 28 [imageview2 setImage:[UIImage imageNamed:@"2.png"]]; 29 [scrollView addSubview:imageview2]; 30 [imageview2 release]; 31 32 UIImageView *imageview3 = [[UIImageView alloc] initWithFrame:CGRectMake(960, 0, 320, 460)]; 33 [imageview3 setImage:[UIImage imageNamed:@"3.png"]]; 34 imageview3.userInteractionEnabled = YES; //打开imageview3的用户交互;否则下面的button无法响应 35 [scrollView addSubview:imageview3]; 36 [imageview3 release]; 37 38 UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];//在imageview3上加载一个透明的button 39 [button setTitle:nil forState:UIControlStateNormal]; 40 [button setFrame:CGRectMake(46, 371, 230, 37)]; 41 [button addTarget:self action:@selector(firstpressed) forControlEvents:UIControlEventTouchUpInside]; 42 [imageview3 addSubview:button]; 43 44 [self.view addSubview:scrollView]; 45 [scrollView release]; 46 } button的方法 1 - (void)firstpressed 2 { 3 [self presentModalViewController:[[[WeiBoViewController alloc] init] autorelease] animated:YES]; //点击button跳转到根视图 4 } 至于添加button是因为我的用户引导最后一个页面有一个画上去的button,写着 开始使用 我在上面添加一个透明的button 用以实现调用方法
这是初始化引导页的方法
下面是俺的做法
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];// Override point for customization after application launch.
//判断是不是第一次启动应用
if(![[NSUserDefaults standardUserDefaults] boolForKey:@"firstLaunch"])
{
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"firstLaunch"];
NSLog(@"第一次启动");
//如果是第一次启动的话,使用UserGuideViewController (用户引导页面) 作为根视图
ViewController *userGuideViewController = [[ViewController alloc] init];
self.window.rootViewController = userGuideViewController;
}
else
{
NSLog(@"不是第一次启动");
//如果不是第一次启动的话,使用LoginViewController作为根视图
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
self.window.rootViewController=[storyboard instantiateInitialViewController];
}
// self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
相关文章推荐
- [POJ 3277]City Horizon
- leetCode 81.Search in Rotated Sorted Array II (旋转数组的搜索II) 解题思路和方法
- 提高工作效率的16条Android开发小经验
- SOAP和WSDL的一些必要知识
- Python中 字典排序、列表排序
- 线性表的顺序存储
- BIPlatform V1.x 用户操作手册出炉
- leetCode 80.Remove Duplicates from Sorted Array II (删除排序数组中的重复II) 解题思路和方法
- js命名规范
- 使用PDO持久化连接
- opcache运行时配置参数详解
- [UVA512]Spreadsheet Tracking[模拟][STL]
- spring+websocket整合(springMVC+spring+MyBatis即SSM框架和websocket技术的整合)
- 双端队列
- Android 四大组件学习之Service四
- HDU 5289 Assignment (RMQ+二分)
- javascript中的事件流,事件处理程序/事件监听器
- AVFoundation理解及开发步骤
- SQL Server事务日志作用大 常见故障轻松除
- Mysql5.6审计功能