iOS App 实现两个window各自运行不同的功能(两个UIWindow)
1、AppDelegate.m自己设置根视图
self.window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 375, 667)];
FirsteAppViewController * mainViewController = [[FirsteAppViewController alloc] init];
UINavigationController * navigationController = [[UINavigationController alloc] initWithRootViewController:mainViewController];
[navigationController setNavigationBarHidden:YES animated:NO];
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
2、FirsteAppViewController的viewDidLoad方法,增加2个UIWindow
UIWindow * window1 = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 375/2, 667)];
UIWindow * window2 = [[UIWindow alloc] initWithFrame:CGRectMake(375/2, 0, 375/2, 667)];
[self.view addSubview:window1];
[self.view addSubview:window2];
SecedeAppViewController * ctl = [[SecedeAppViewController alloc] init];
[ctl.view setBackgroundColor:[UIColor blueColor]];
UINavigationController * navigationController1 = [[UINavigationController alloc] initWithRootViewController:ctl];
[navigationController1 setNavigationBarHidden:YES animated:NO];
window1.rootViewController = navigationController1;
[window1 makeKeyAndVisible];
SecedeAppViewController * mainViewController = [[SecedeAppViewController alloc] init];
[mainViewController.view setBackgroundColor:[UIColor yellowColor]];
UINavigationController * navigationController2 = [[UINavigationController alloc] initWithRootViewController:mainViewController];
[navigationController2 setNavigationBarHidden:YES animated:NO];
window2.rootViewController = navigationController2;
[window2 makeKeyAndVisible];
“`
3运行,效果如下图所示:
image.png
4、GitHub源码:
HuiTongZhiYuan/TestTwoViewController
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是摆设,本站源码仅提供给会员学习使用!
7. 如遇到加密压缩包,请使用360解压,如遇到无法解压的请联系管理员
开心源码网 » iOS App 实现两个window各自运行不同的功能(两个UIWindow)