Search Unity

add UIViewController.view to Unity view

Discussion in 'iOS and tvOS' started by detournment_19, Jul 14, 2017.

  1. detournment_19

    detournment_19

    Joined:
    Jan 20, 2015
    Posts:
    22
    Hi, it's been a few years since I let needed to add a custom view controller on top of the Unity view. It used to be I could call:

    UIWindow *window = [[[UIApplication sharedApplication] keyWindow];
    UIViewController *theController = window.rootViewController;

    And attach my view controller's view to that. But now I am seeing that window as nil. Is there a newer way to do this?
     
  2. detournment_19

    detournment_19

    Joined:
    Jan 20, 2015
    Posts:
    22
    I see. UnityGetGLViewController() seems to be the current flavor.
     
  3. aihodge

    aihodge

    Joined:
    Nov 23, 2014
    Posts:
    163
    Code (CSharp):
    1. [UnityGetGLViewController().view addSubview:customView];
    A quick way to do this is to load your view from a .xib, set its frame, and add it to Unity’s view with the above line.