我的应用程序通过 plist 条目 + appdelegate 中的这个隐藏了状态栏:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[application setStatusBarHidden:YES];
当我的 View 加载时,状态栏是隐藏的。只要我点击并将焦点放在搜索栏上,状态栏就会出现。当搜索栏失去焦点时,状态栏再次消失。
当搜索栏获得焦点时,如何防止状态栏出现?
最佳答案
当在父 Controller 上点击搜索栏时,如何显示(隐藏/显示)状态栏的控制权将交给搜索 Controller 。
在 info.plist 中将“View controller-based status bar appearance”设置为 NO 在一定程度上起作用,防止在点击搜索时出现状态栏,尽管这也阻止了状态栏出现在其他 View Controller 上;不受欢迎的行为。
相反,我认为将 UISearchController 子类化并覆盖其中的 prefersStatusBarHidden 方法更为准确。 (我还在 info.plist 中将“基于 View Controller 的状态栏外观”设置为 YES)。
所以:
@implementation MySearchController
// Override so it does not show the status bar when active
- (BOOL)prefersStatusBarHidden {
return YES;
}
...
@end
在呈现 Controller 中:
_searchController = [[MySearchController alloc] initWithSearchResultsController:nil];
关于ios - 当搜索栏具有焦点时,UISearchController 不会尊重隐藏的状态栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31041976/