gpt4 book ai didi

ios - 新的 UIWindow 不显示

转载 作者:行者123 更新时间:2023-11-28 22:03:37 25 4
gpt4 key购买 nike

我正在尝试创建一个新的 UIWindow 来覆盖整个屏幕,包括状态栏。我让它在按下按钮时出现,但它只是在屏幕上快速闪烁然后消失。我做错了什么?

MenuTableViewController *menu = [[MenuTableViewController alloc]initWithNibName:@"MenuTableViewController" bundle:nil];

UIWindow *menuWindow = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
menuWindow.backgroundColor = [UIColor clearColor];
menuWindow.windowLevel = UIWindowLevelStatusBar;
menuWindow.rootViewController = menu;
[menuWindow addSubview:menu.view];
[menuWindow makeKeyAndVisible];
menuWindow.hidden = NO;

最佳答案

我通过将 @property (nonatomic, strong) UIWindow *menuWindow; 添加到我的头文件来让它工作。这是我的 showMenu 和 closeMenu 方法的样子。

- (void)showMenu
{
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;

UIButton *closeMenuButton = [UIButton buttonWithType:UIButtonTypeCustom];
[closeMenuButton setFrame:CGRectMake(250, 10, 50, 50)];
[closeMenuButton setImage:[UIImage imageNamed:@"close"] forState:UIControlStateNormal];
[closeMenuButton addTarget:self action:@selector(closeMenu) forControlEvents:UIControlEventTouchUpInside];

blurredView = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, screenWidth, screenHeight)];
[blurredView setBarStyle:UIBarStyleBlack];

MenuTableViewController *menu = [[MenuTableViewController alloc]initWithNibName:@"MenuTableViewController" bundle:nil];
menu.view.frame = CGRectMake(0, 30, screenWidth, screenHeight - 50);

menuWindow = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
menuWindow.backgroundColor = [UIColor clearColor];
menuWindow.windowLevel = UIWindowLevelStatusBar;
menuWindow.rootViewController = menu;
[menuWindow addSubview:blurredView];
[blurredView addSubview:closeMenuButton];
[blurredView addSubview:menu.view];
[menuWindow makeKeyAndVisible];
}

- (void)closeMenu
{
menuWindow.hidden = YES;
menuWindow = nil;
}

关于ios - 新的 UIWindow 不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24518013/

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