簡體   English   中英

IOS:如何在呈現的模態視圖 controller 之上放置一些視圖?

[英]IOS: How to put some view on top of presented modal view controller?

我在 AppDelegate class 中添加了一個活動視圖以點擊欄:

[self.mainTabBar.view addSubview: spinner];

當存在連接問題時,它在每個視圖中都可見 controller 並且正在旋轉。 在某些視圖 controller 有一些按鈕,用於呈現一些模態視圖 controller。 該模態視圖 controller 與微調器重疊。 如何使該微調器始終位於所有視圖之上,或者至少位於模態視圖 controller 之上? 我試圖在呈現模態視圖 controller 的視圖 controller 中做出這樣的事情:

[self presentModalViewController:selectionViewController animated:YES];
[self.view bringSubviewToFront:[self.tabBarController.view viewWithTag:15]];

不工作。

將視圖添加到主窗口。

UIWindow* mainWindow = [[UIApplication sharedApplication] keyWindow];
[mainWindow addSubview: spinner];

雖然phix23的答案是正確的,但這是一個更完整的例子:

//The view you want to present
UIViewController *viewControllerYouWantToPresentOnTop = [[UIViewController alloc] initWithNibName:nil bundle:nil];

//Create transparent host view for presenting the above view
UIWindow* mainWindow = [[UIApplication sharedApplication] keyWindow];
UIViewController *viewControllerForPresentation = [[UIViewController alloc] init];
[[viewControllerForPresentation view] setBackgroundColor:[UIColor clearColor]];
[[viewControllerForPresentation view] setOpaque:FALSE];
[mainWindow addSubview:[viewControllerForPresentation view]];

//Make your transparent view controller present your actual view controller
[viewControllerForPresentation presentViewController:viewControllerYouWantToPresentOnTop animated:TRUE];

當你不再需要這些時,請記得自己清理干凈。

此代碼可以在您的應用程序的任何位置使用,甚至是庫:)

應用程序通常在其整個生命周期內在單個窗口中顯示其內容。 但是在某些情況下,可能會使用額外的窗口在其他所有內容之上添加內容。 Apple通過在單獨的窗口中添加UIAlertView確保UIAlertView始終保持最佳狀態。

UIView *contentView = [[UIView alloc] initWithFrame:contentFrame];
contentView.backgroundColor = [UIColor greenColor];
UIWindow *window = [[UIWindow alloc] initWithFrame:CGRectMake(x,y,contentFrame.size.width, contentFrame.size.height)];
window.windowLevel = UIWindowLevelAlert;
[window addSubview:contentView];
[window makeKeyAndVisible];

通過設置window.hidden = Yes or No顯示和隱藏窗口window.hidden = Yes or No根據需要。 這將始終在應用程序中的所有其他內容上顯示您的contentView

如上所述,將視圖放置到 keyWindow。 您可能還需要將模態視圖的演示樣式設置為當前上下文,否則,它仍然可以彈出頂部

模態控制器位於完全不同的層中,您不能使呈現控制器的任何子視圖與其重疊。

使用帶有微調器的UIAlertView 警報顯示在一個層中,該層甚至與模態控制器重疊。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM