Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add multiple UIWindow

I am adding a new UIWIndow over another to display a view, but it is not showing anything and the screen just gets a little blurred. Here is the code:

UIWindow* topWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
[topWindow setWindowLevel:UIWindowLevelNormal];

CGFloat statusBarHeight = [UIApplication sharedApplication].statusBarFrame.size.height;

UIViewController* viewController = [[UIViewController alloc] init];
UIView* overlay = [[UIView alloc] initWithFrame:CGRectMake(0, -statusBarHeight,   viewController.view.frame.size.width, statusBarHeight - 1)];
[overlay setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
[overlay setBackgroundColor:[UIColor whiteColor]];
[viewController.view addSubview:overlay];
[topWindow setRootViewController:viewController];

[topWindow setHidden:NO];
[topWindow setUserInteractionEnabled:NO];
[topWindow makeKeyAndVisible];

viewController = nil;

overlay = nil;

What am I doing wrong?

like image 280
Hassy Avatar asked Dec 21 '25 10:12

Hassy


2 Answers

I wanna do like you too.

@implementation TAAppDelegate {
    UIWindow *win;
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.

    double delayInSeconds = 2.0;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        win = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        win.rootViewController = [UIViewController new];
        win.rootViewController.view.backgroundColor = [UIColor whiteColor];
        win.rootViewController.view.alpha = 0.5;
        [win makeKeyAndVisible];
    });
    return YES;
}
.....

And I did it. I think you should retain your new UIWindows. (I'm using ARC so I defined 1 local var to retain it)

Good luck!

like image 119
Tony Avatar answered Dec 23 '25 00:12

Tony


Set windowLevel property to another value. I usually use:

topWindow.windowLevel = UIWindowLevelAlert + 1;
like image 33
vietstone Avatar answered Dec 22 '25 23:12

vietstone