在页面内增加tableView 和 UISearchController
[self.view addSubview:self.tableView];
self.tableView.tableHeaderView = self.searchController.searchBar;
并对UINavgationBar设置translucent属性后
self.navigationBar.translucent = NO;
按如下设置配置searchController
-(UITableView *)tableView{
if (_tableView == nil) {
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, UIScreenHeight - 44)];
}
return _tableView;
}
-(UISearchController *)searchController{
if (_searchController == nil) {
_searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
_searchController.searchResultsUpdater = self;
[_searchController setHidesNavigationBarDuringPresentation:YES];
[_searchController setDimsBackgroundDuringPresentation:YES];
[_searchController.searchBar setFrame:CGRectMake(0, 0, UIScreenWidth, 44)];
}
return _searchController;
}
此时,点击searchbar,正常应该会,navbar会消失,searchbar动画上移。但实际情况是,searchbar直接移到了屏幕外面!!!!!!
删除下面这句就又正常了。
self.navigationBar.translucent = NO;
请大神搭个Demo试试,这个问题。感觉是iOS的问题啊!!!
似乎发现了原因。translucent属性的设置与否,与self.view的Frame的位置相关。当translucent设为NO时,self.view的位置,从navbar下边界开始。反之亦然。