Новый UIWindow не будет отображаться

Я пытаюсь создать новый 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;

person raginggoat    schedule 01.07.2014    source источник


Ответы (1)


Я заработал, добавив @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;
}
person raginggoat    schedule 02.07.2014