how to add a view over window in uiviewcontroller

前端 未结 4 657
轮回少年
轮回少年 2021-01-24 20:19

Is it possible to add a subview over the window from a uiviewcontroller and then removing that also?

Thanks Pankaj

相关标签:
4条回答
  • 2021-01-24 20:52

    You can use like this too.

    For adding:

    [[UIApplication sharedApplication].keyWindow.rootViewController addChildViewController:childVC];
    [[UIApplication sharedApplication].keyWindow.rootViewController.view addSubview:childVC.view];
    

    For removing:

    [childVC.view removeFromSuperview];
    [childVC removeFromParentViewController];
    
    0 讨论(0)
  • 2021-01-24 20:58

    [[UIApplication sharedApplication].keyWindow.subviews.firstObject addSubview:yourView];

    if you are using an iPad in landscape you should add your view over ther window's first subview.

    @Yuvaraj.M this is the solution to your problem

    0 讨论(0)
  • 2021-01-24 21:07

    It works for me:

    [[[[UIApplication sharedApplication] windows] objectAtIndex:0] addSubview:yourView];
    
    0 讨论(0)
  • 2021-01-24 21:11

    Not sure what you mean...

    [self.view addSubview:yoursubview];
    
    [yoursubview removeFromSuperview];
    

    Over the window:

    [[[UIApplication sharedApplication] keyWindow] addSubview:yourview];
    
    0 讨论(0)
提交回复
热议问题