简体   繁体   English

轻按时,UISearchBar滑开

[英]UISearchBar slides away when tapped

I have a search bar as a title view for my navigation bar. 我有一个搜索栏作为导航栏的标题视图。

And it looks like this, the way I want it to look like: 它看起来像这样,我希望它看起来像这样:

点击前的搜索栏

But when I tap on it, it just slides to top and becomes inaccessible 但是当我点击它时,它只是滑到顶部而变得无法访问

在此处输入图片说明

Here is the code I used to configure it: 这是我用来配置它的代码:

- (void)configureSearchBar
{
    self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
    self.searchController.searchBar.delegate = self;
    self.navigationItem.titleView = self.searchController.searchBar;
}

Is there any way to fix this kind of problem? 有什么办法可以解决这种问题?

self.searchController.hidesNavigationBarDuringPresentation = NO

Adding this line has solved this problem or me. 添加这一行已经解决了这个问题或我。 The reason of this problem was that my search bar was set as a title view for my navigation bar and the property hidesNavigationBarDuringPresentation was set to YES by default. 出现此问题的原因是,我的搜索栏被设置为导航栏的标题视图,并且属性hidesNavigationBarDuringPresentation默认情况下设置为YES Setting this property to NO solves this kind of problem. 将此属性设置为NO可解决此类问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM