2015-06-17 64 views
5

我有一個應用程序,其中包含Xcode Storyboard UI和託管Unity3D/Vuforia項目的其中一個視圖。我之前使用Unity 4.6.2和Vuforia 3.0.9,並且已經使用以下方法實現了UnityAppDelegate子類,這允許我執行此操作。iOS ViewController層次結構更改爲Unity 4.6.5和Vuforia 4.2更新

-(void)createViewHierarchyImpl 
{ 
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"AR" bundle:nil]; 
    PPARStartViewController * helloVC = (PPARStartViewController *)[sb instantiateViewControllerWithIdentifier:@"StartController"]; 

    self.navController = [[UINavigationController alloc] initWithRootViewControllier:helloVC]; 
    self.navController.navigationBarHidden = YES; 

    _rootController = self.navController; 
    _rootView = self.navController.view; 

} 

我也寫了一個擴展的UINavigationController進一步處理旋轉變化了我的看法棧(加載不同的圖像取決於方向)。

但是,我必須更新我的應用程序才能使用Unity3D 4.6.5和Vuforia 4.2,因爲要將應用程序提交到App Store需要64位。這導致了一些問題。

  1. 上述createViewHierarchyImpl方法不再適用於該狀態。它拋出一個運行時錯誤:

終止應用程序由於未捕獲的異常「UIViewControllerHierarchyInconsistency」,理由是:「子視圖控制器:PPARStartViewController:0x17dc3070應該有父視圖控制器:UnityDefaultViewController:0x1c083200但實際的父是:UINavigationController的:0x17dc3820 '

我不得不它更改爲以下:

-(void)createViewHierarchyImpl 
    { 
     _rootController = [[UIViewController alloc] init]; 
     _rootView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
     _rootController.view = _rootView; 

     UIStoryboard *sb = [UIStoryboard storyboardWithName:@"AR" bundle:nil]; 
     PPARStartViewController * helloVC = (PPARStartViewController *)[sb instantiateViewControllerWithIdentifier:@"StartController"]; 

     self.navController = [[UINavigationController alloc] initWithRootViewController:helloVC]; 
     [_rootView addSubview:self.navController.view]; 

     self.navController.navigationBarHidden = YES; 
    } 
  • 從之前做上述變化層次,以及我的UINavigationControl ler擴展類不再捕獲輪換調用。他們現在被UnityDefaultViewController捕獲。我試圖以相同的方式擴展這個類,但是在運行時,視圖控制器似乎沒有孩子,父母或與當前加載的視圖的任何關係。
  • 最後,可能無關,但我確定它可能是,Vuforia視圖不能正確旋轉。肖像和LandscapeLeft都很好,但在LandscapeRight和PortraitUpsidedown中,相機饋送會翻轉。
  • 解決方案,我希望:

    1. 理想的情況下,我希望有人能告訴我,我的問題1的原始代碼是可能的,我只是失去了一些東西,修復的父母關係我的視圖控制器。
    2. 如果不是,那麼我需要找出如何將旋轉通知從UnityDefaultViewController傳遞到我的UINavigationController。
    3. 最後,有沒有辦法停止UnityPlayer視圖旋轉?除了相機饋送和增強內容之外,沒有其他任何內容,因此實際視圖甚至不需要旋轉。
    +1

    我有問題,也有Vuforia 4.x版升級到Unity 5時,但他們與其他iOS插件。在找出發生了什麼的過程中,我看到關於'createViewHierarchy'的一些註釋不再使用。也許它有助於檢查生成的類/頭文件_Classes/UI/UnityAppController + ViewHandling.h_中的註釋。如果你使用IMPL_APP_CONTROLLER_SUBCLASS因爲Vuforia做,其中一個是用到底 – Kay

    +0

    我仍在使用統一4.6.6未定義行爲從而結束相同的,所以我不知道,註冊自己的應用程序控制器照顧,如果候補createViewHierarchy可用。不過明天我會看看這些。 另外,我使用我自己的應用程序控制器,但在更新後將它合併到Vuforia中。 – Dover8

    +0

    謝謝@Kay,您的評論確實將我發送到了答案的路徑上,我在下面詳細介紹了答案。 – Dover8

    回答

    0

    縱觀UnityAppController + ViewHandling.mm並將其與Unity 4.6以前的舊版本進行比較,我能夠想出一個解決方案。

    在VuforiaNativeRendererController.mm中,我還實現了createAutorotatingUnityViewController方法。在這裏我返回一個UnityDefaultViewController的新實例(這是createViewHierarchyImpl用來做的)。

    -(UIViewController*)createAutorotatingUnityViewController 
    { 
        return [[UnityDefaultViewController alloc] init]; 
    } 
    

    然後在UnityAppController中。毫米我刪除從新checkOrientationRequest方法的代碼,並在onForcedOrientation交換了

    [self transitionToViewController:[self createRootViewController]]; 
    

    來的老辦法:

    OrientView(_rootController, _rootView, orient); 
    [_rootView layoutSubviews]; 
    

    這一切後,我能夠用我的原代碼createViewHierarchyImpl和保留對我的輪換的控制權。

    的AR相機視圖仍然翻轉一些輪換,但現在我相信這是一個單獨的問題。

    [編輯] 我想通了,爲什麼AR攝影機視圖沒有定向。我需要通過旋轉通知到舉行的UnityView作爲子視圖的視圖 - 控制,然後調用

    [subView willRotateTo:ConvertToUnityScreenOrientation(toInterfaceOrientation, 0)]; 
    

    現在所有旋轉都如預期運行。 :)