简体   繁体   中英

ViewController Only Presented after User Touches the Screen

I have an app in which I present a menu modally. Then, when the user selects a menu option, the menu dismisses itself and upon completion, presents another view modally according to what button the user selected.

This method worked flawlessly before, but since iOS 13 it behaves weirdly. Basically, it would not present the second view until the user touches the screen, and I cannot for the life of me find out why it behaves this way.

Here is my code (I added logs where the flow stops):

- (void) dismissPopUpMenu:(UIButton *)sender {
    [self dismissViewControllerAnimated:NO completion:^{        
        if ( (sender.tag == 13 ) {
            [self openPopUpWindow:sender];
        }
    }];
}

- (void) openPopUpWindow:(UIButton *)sender {
    interactionDisabledLayer.alpha              = 1.0f;

    PopUpViewController *popUpController        = [[PopUpViewController alloc] initWithPopUp:sender.tag];
    popUpController.delegate                    = self;

    NSLog(@"We get to here without problems.");

    [self presentViewController:popUpController animated:NO completion:^{
        NSLog(@"It only enters here if we touch the screen.");
        self->interactionDisabledLayer.alpha          = 0.0f;
    }];
}

Update: Delaying the code with a timer help, but I consider it a dirty hack and would like to find a better solution.

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.1f * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
        [self presentViewController:popUpController animated:NO completion:^{
            self->interactionDisabledLayer.alpha          = 0.0f;
        }];
    });

Delaying the code that presents the second UIViewController with a timer seem to help, but it is a rather dirty hack, and I would like to find a better workaround. If anyone has a proper solution, please post it as an answer and I will accept it as best.

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.1f * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
        [self presentViewController:popUpController animated:NO completion:^{
            self->interactionDisabledLayer.alpha          = 0.0f;
        }];
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM