我有两个 View Controller ,每个包含 UISearchController
和 UITableView
. viewDidLoad
中的代码是:
SearchResultsTableViewController *searchResultController = [[SearchResultsTableViewController alloc]initWithNibName:@"SearchResultsTableViewController" bundle:nil];
UINavigationController *navSearchResultsController = [[UINavigationController alloc] initWithRootViewController:searchResultController];
self.searchController = [[UISearchController alloc] initWithSearchResultsController:navSearchResultsController];
self.searchController.searchResultsUpdater = self;
self.searchController.dimsBackgroundDuringPresentation = YES;
[self.searchController.searchBar sizeToFit];
self.searchController.searchBar.delegate = self;
self.searchController.delegate = self;
self.tableView.tableHeaderView = self.searchController.searchBar;
self.tableView.userInteractionEnabled = YES;
第一个 View Controller 是
rootViewController
,完美运行,没有任何问题。第二个 View Controller 正在通过基于段选择的导航 Controller 推送。[self.navigationController pushViewController:self.vc];
第二个 View Controller 只有一个问题。当我点击
searchBar
,它动画到顶部并在导航栏下方,而第一个动画在其位置动画并且不上升。谁能告诉我如何禁用这个动画?
我想保留
searchBar
搜索时在同一个地方。两个 View Controller 的实现完全相同。为什么每个人的行为都不一样?谢谢,
最佳答案
设置 hidesNavigationBarDuringPresentation
boolean on the UISearchController
至NO
.
self.searchController.hidesNavigationBarDuringPresentation = NO;
或试试 this answer ,这听起来与您正在尝试做的事情相似。但你可能想调整这条线:
[super setActive: visible animated: animated]; // instead of passing animated, pass NO
关于ios - UISearchBar 在导航栏下方的动画不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34276475/