gpt4 book ai didi

ios - 在主窗口上创建一个新的 UIWindow

转载 作者:IT王子 更新时间:2023-10-29 07:46:21 46 4
gpt4 key购买 nike

在我的应用程序中,我想在主 UIWindow 上创建一个新的 UIWindow,我写如下,但它不起作用。首先,我创建一个 UIWindow 作为主窗口,然后将其设置为键和可见,然后创建一个新的 UIWindow 覆盖,但没有任何反应。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor redColor];
ViewController *vc = [[ViewController alloc]initWithNibName:@"ViewController" bundle:nil];
self.window.rootViewController = vc;
[self.window makeKeyAndVisible];
UIWindow *window1 = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 320, 320)];
window1.backgroundColor = [UIColor redColor];
window1.windowLevel = UIWindowLevelAlert;
[window1 makeKeyAndVisible];
return YES;
}

最佳答案

UIWindow *window1 = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 320, 320)];
window1.backgroundColor = [UIColor redColor];
window1.windowLevel = UIWindowLevelAlert;
[window1 makeKeyAndVisible];

终于知道为什么不行了,因为window1是一个method var,method执行完就丢失了。所以我为它声明了一个新的@property,如

@property (strong, nonatomic) UIWindow *window2;

和像这样更改代码

UIWindow *window2 = [[UIWindow alloc] initWithFrame:CGRectMake(0, 80, 320, 320)];
window2.backgroundColor = [UIColor redColor];
window2.windowLevel = UIWindowLevelAlert;
self.window2 = window2;
[window2 makeKeyAndVisible];

它有效!

关于ios - 在主窗口上创建一个新的 UIWindow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19995526/

46 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com