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?
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!
Set windowLevel property to another value. I usually use:
topWindow.windowLevel = UIWindowLevelAlert + 1;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With