美文网首页iOS UI开发程序员
iOS App 实现两个window各自运行不同的功能(两个UI

iOS App 实现两个window各自运行不同的功能(两个UI

作者: 刘明洋 | 来源:发表于2019-04-22 17:18 被阅读24次

    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源码:

    https://github.com/HuiTongZhiYuan/TestTwoViewController

    相关文章

      网友评论

        本文标题:iOS App 实现两个window各自运行不同的功能(两个UI

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