![](/img/trans.png)
[英]How to setup a relationship between the presenting View Controller and the presented View Controller?
[英]Presented view controller place under presenting view controller
我構建了一個本地 iOS 框架,導入到 Unity 項目中,以管理游戲帳戶(登錄、注銷、注冊等)。 當我調用框架方法來顯示登錄屏幕時,它會顯示但放在顯示視圖 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;
}
topMostController返回UnityDefaultViewController(也是keyWindow的rootViewController),showViewController的輸入是我的SigninViewController,為什么放在UnityDefaultViewController下面? 之前在幾個Unity游戲中導入過這個框架,但是第一次看到這個問題。
[更新] 檢查代碼后,Unity 引擎生成的一些代碼行(我的 Unity 開發人員說的)導致了這個問題:
- (void)showGameUI
{
...
[_window addSubview: _rootView]; //this line cause the issue
_window.rootViewController = _rootController;
[_window bringSubviewToFront: _rootView];
...
}
誰能確認這行代碼是由 Unity 引擎生成的? 我試圖評論那條線,問題消失了,我還沒有發現其他問題,但是可以嗎?
幾個小時后,我終於通過將呈現樣式從 UIModalPresentationOverCurrentContext 更改為 UIModalPresentationOverFullScreen 來修復它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.