打开搜索栏时导航栏隐藏

Posted

技术标签:

【中文标题】打开搜索栏时导航栏隐藏【英文标题】:Navigation bar is hiding when i open my search bar 【发布时间】:2015-12-01 15:32:40 【问题描述】:

我的Navigation Bar 中嵌入了一个UISearchController,当我单击它时,整个导航栏都会离开屏幕,直到我按下屏幕上的另一个区域然后它又回来了。这是视频的a link。 (视频可能已经上传了,所以给它一些时间,链接确实有效)

    self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
    self.searchController.dimsBackgroundDuringPresentation = NO;
    // Use the current view controller to update the search results.
    self.searchController.searchResultsUpdater = self;
    //Setting Style
    self.searchController.searchBar.barStyle = UIBarStyleBlack;
    self.searchController.searchBar.barTintColor = [UIColor colorWithRed:49.0/255.0 green:49.0/255.0 blue:61.0/255.0 alpha:1.0];
    self.searchController.searchBar.backgroundImage = [UIImage imageNamed:@"BG"];
    self.searchController.searchBar.placeholder = @"Search Artists, Songs, Albums etc.";
    self.searchController.searchBar.keyboardAppearance = UIKeyboardAppearanceDark;
    [self.searchController.searchBar sizeToFit];
    self.definesPresentationContext = YES;
    self.searchController.searchBar.tintColor = self.view.window.tintColor;
    [self.searchController.searchBar setTintColor:[UIColor colorWithRed:(226.0/255.0) green:(56.0/255.0) blue:(83.0/255.0) alpha:(1.0)]];
    self.searchController.searchBar.delegate = self;
    self.navigationItem.titleView = self.searchController.searchBar;


- (void)updateSearchResultsForSearchController:(UISearchController *)searchController
    NSString *searchString = searchController.searchBar.text;
    NSLog(@"You searched for %@", searchString);
    [searchResultsTableView reloadData];
 

-(void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
    [self.view addSubview:searchResultsTableView];

【问题讨论】:

你需要包含一些代码,在这里寻找一些建议:***.com/help/mcve 抱歉,请查看更新的答案 【参考方案1】:

您需要添加以下内容

self.searchController.hidesNavigationBarDuringPresentation = NO;

停止 UISearchController 在激活时隐藏导航栏 (ref docs link)。

【讨论】:

以上是关于打开搜索栏时导航栏隐藏的主要内容,如果未能解决你的问题,请参考以下文章

iOS:在导航栏中显示搜索栏时隐藏范围栏

隐藏导航栏时的假状态栏颜色

UITableViewController 隐藏导航栏[搜索栏]

iOS 7隐藏导航栏时如何更改状态栏的颜色?

搜索显示控制器如何隐藏导航栏?

在iOS 7中隐藏导航栏时,如何更改状态栏的颜色?