Presented view controller place under presenting view controller

Presented view controller place under presenting view controller

Problem Description:

I build a native iOS framework, which imported to a Unity project, to manage game account (login, logout, signup,…). When I call framework method to show login screen, it’s presented but place under presenting view controller.

- (void)showViewController:(UIViewController *)controller {
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:controller];
    nav.navigationBarHidden = YES;
   [nav setModalPresentationStyle: UIModalPresentationOverCurrentContext];
   [[UIViewController topMostController] presentViewController:nav animated:YES completion: nil];
+ (UIViewController*) topMostController {
    UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController;
    while (topController.presentedViewController) {
      topController = topController.presentedViewController;
    return topController;

enter image description here

topMostController return UnityDefaultViewController (it’s also rootViewController of keyWindow), and input of showViewController is my SigninViewController, why it’s place under UnityDefaultViewController? I have imported this framework to a few Unity game before, but this is the first time I saw this issue.

[Update] After review code, there is some line of code which generated by Unity engine (my Unity dev guy said that) cause that issue:

- (void)showGameUI
   [_window addSubview: _rootView]; //this line cause the issue
   _window.rootViewController = _rootController;
   [_window bringSubviewToFront: _rootView];

Can anyone confirm these line of code are generated by Unity engine? I have tried to comment that line, issue gone and I haven’t found other issue yet, but is that ok?

Solution – 1

After many hours, finally I fixed it by changing presentation style from UIModalPresentationOverCurrentContext to UIModalPresentationOverFullScreen.

Rate this post
We use cookies in order to give you the best possible experience on our website. By continuing to use this site, you agree to our use of cookies.