添加多个UIWindow

我正在添加一个新的UIWIndow来显示一个视图,但它没有显示任何内容,屏幕只是有点模糊。 这是代码:

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; 

我究竟做错了什么?

我也喜欢你。

 @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; } ..... 

我做到了。 我认为你应该保留你的新UIWindows 。 (我正在使用ARC所以我定义了1个本地var来保留它)

祝你好运!

将windowLevel属性设置为另一个值。 我通常使用:

 topWindow.windowLevel = UIWindowLevelAlert + 1; 

你为什么要创建第二个窗口来叠加主窗口?

来自Apple文档:

“UIWindow对象协调屏幕上一个或多个视图的呈现。大多数应用程序只有一个窗口,在主屏幕上显示内容,但应用程序可能有一个额外的窗口显示在外部显示器上的内容。”

您应该以模态方式或使用“UIViewController包含”来呈现您的其他viewController。 一切都在一个窗口内。