美文网首页#iOS#HeminWon
iOS 多个window叠加

iOS 多个window叠加

作者: 草原烈鹰 | 来源:发表于2017-01-13 14:57 被阅读1425次
window,多个时,[UIApplication sharedApplication].windows[0]和[[UIApplication sharedApplication] delegate] window]获取的是最开始创建的window,而[UIApplication sharedApplication].keyWindow获取的是当前显示的window,不一定是最初的window。window之间的切换时可以的,让不需要出现的window隐藏,不过只有当前显示的window才能响应事件,window隐藏,它上面所添加的VIew都会隐藏。就是window不隐藏,它后面有window添加,那么相当于开始的是隐藏的,它上面的东西不会显示出来。

直接怼代码:


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    wgj01ViewController *mainTabBarController = [[wgj01ViewController alloc] init];
    UINavigationController *naBar = [[UINavigationController alloc] initWithRootViewController:mainTabBarController];
    
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.rootViewController = naBar;
    [self.window makeKeyAndVisible];
    
    NSLog(@"root1N:%@,,root1VC:%@",naBar,mainTabBarController);
    
    self.secondWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    wgj02ViewController *secondVC = [[wgj02ViewController alloc] init];
    self.secondWindow.rootViewController = secondVC;
    [self.secondWindow makeKeyAndVisible];
    self.secondWindow.backgroundColor = [UIColor orangeColor];
//    [self.window addSubview:self.secondWindow];
    
    NSLog(@"root2:%@",secondVC);
    
     NSLog(@"keyW:%@", [UIApplication sharedApplication].keyWindow);
    NSLog(@"windows:count:%ld,具体:%@\n%@",[UIApplication sharedApplication].windows.count ,[UIApplication sharedApplication].windows[0],[UIApplication sharedApplication].windows[1]);
    
    NSLog(@"\n\n\ndelegateW:%@\n%@", [[[UIApplication sharedApplication] delegate] window],[UIApplication sharedApplication].windows[0].rootViewController);
    
    return YES;
}


#import "wgj01ViewController.h"
#import "wgj01push1.h"

@implementation wgj01ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(10, 50, 200, 50)];
    button.backgroundColor = [UIColor orangeColor];
    [button setTitle:@"wgj01ViewControllerAddView" forState:(UIControlStateNormal)];
    [button addTarget:self action:@selector(clickBtn) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:button];
    
    
    UIButton *button1 = [[UIButton alloc] initWithFrame:CGRectMake(10, 250, 200, 50)];
    button1.backgroundColor = [UIColor orangeColor];
    [button1 setTitle:@"wgj01ViewControllerPush" forState:(UIControlStateNormal)];
    [button1 addTarget:self action:@selector(clickBtnPush) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:button1];
}

- (void)clickBtn
{
    NSLog(@"点击了wgj01ViewController");
    NSLog(@"\n\nself.view.window:%@\n,keyWindow:%@\n,delegateWindow:%@\n,count:%lu\n\n%@\n%@\n",self.view.window,[UIApplication sharedApplication].keyWindow,[[[UIApplication sharedApplication] delegate] window],(unsigned long)[UIApplication sharedApplication].windows.count,[UIApplication sharedApplication].windows[0],[UIApplication sharedApplication].windows[1]);
    
    
    UIView *coverV = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 100, 100)];
    coverV.backgroundColor = [UIColor redColor];
    [[UIApplication sharedApplication].windows[0] addSubview:coverV];
    
    
}

- (void)clickBtnPush
{
    wgj01push1 *ss = [[wgj01push1 alloc] init];
    [self.navigationController pushViewController:ss animated:YES];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end


\#import "wgj02ViewController.h"

@implementation wgj02ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(10, 150, 200, 50)];
    button.backgroundColor = [UIColor orangeColor];
    [button setTitle:@"wgj02ViewController" forState:(UIControlStateNormal)];
    [button addTarget:self action:@selector(clickBtn) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:button];
}

- (void)clickBtn
{
//    UIView *coverV = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 100, 100)];
//    coverV.backgroundColor = [UIColor redColor];
//    [[UIApplication sharedApplication].windows[0] addSubview:coverV];
//    
//    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        NSLog(@"点击了wgj02ViewController");
        NSLog(@"\n\n%@",self.view.window);
        [self.view.window resignKeyWindow];
        NSLog(@"%@,%@",[[[UIApplication sharedApplication] delegate] window],[UIApplication sharedApplication].keyWindow  );
        
        self.view.window.hidden = YES;
        
        NSLog(@"%@,%@",[[[UIApplication sharedApplication] delegate] window],[UIApplication sharedApplication].keyWindow  );
//    });
    

    
//    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 300, 300)];
//    view.backgroundColor = [UIColor orangeColor];
//    [[[UIApplication sharedApplication].delegate window] addSubview:view];
//    
//    UIWindow *window = [[UIWindow alloc] initWithFrame:CGRectMake(100, 200, 200, 200)];
//    [window addSubview:view];
//    [window makeKeyAndVisible];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end


#import "wgj01push1.h"

@implementation wgj01push1
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(10, 350, 200, 50)];
    button.backgroundColor = [UIColor orangeColor];
    [button setTitle:@"wgj01push1Title" forState:(UIControlStateNormal)];
    [button addTarget:self action:@selector(clickBtn) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:button];
}
@end

相关文章

  • iOS 多个window叠加

    window,多个时,[UIApplication sharedApplication].windows[0]和[...

  • iOS 多个window弹窗管理

    App里总会有很多的弹窗,为了美观,大多数弹窗都需要盖住导航栏;这时弹窗会添加到window上以满足需求。但添加到...

  • iOS多个控件视图叠加生成图片并保存本地

    适用人员:iOS开发人员。本文内容:iOS如何叠加多个视图生成图片,并保存到本地。 第一步:希望生成图片的所有视图...

  • iOS 离屏渲染

    1. 什么是离屏渲染? iOS 中对于图层的绘制遵循“画家算法”,对于叠加了多个 layer 的图形,会先绘制最底...

  • iOS开发备忘笔记 (3)

    一、iOS应用的 UIWindow 各种方式获取的 window: 自己新建 window: window 对象释...

  • TMUX - terminal multiplexer

    前序: 布道 Tmux 三个术语: session: 管理多个window的会话 window: 一个window...

  • pytest的fixture传参数

    fixture传多个参数 多个fixtur只加一个装饰器 多个fixtur叠加装饰器

  • UIKit-UIWindow详解

    这篇关于UIWindow的文章是在iOS7版本时研究发布的,一个APP同时创建多个window本就不被苹果所支持,...

  • window设置多个SSH

    系统介绍单个SSH秘钥的设置方法。多个guthub账号又该如何绑定同台电脑。 网上看了很多版本的PC设置SSH-k...

  • Android笔记——用layer-list和shape画加号

    首先layer-list可实现多个drawable叠加效果,每个drawable都写在item中以实现叠加,ite...

网友评论

  • 笑笑菜鸟:NSLog(@"windows:count:%ld,具体:%@\n%@",[UIApplication sharedApplication].windows.count ,[UIApplication sharedApplication].windows[0],[UIApplication sharedApplication].windows[1]);
    怎么会有3个window?

本文标题:iOS 多个window叠加

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