ios - UISearchBar 在导航栏下方的动画不正确

标签 ios objective-c uitableview uisearchcontroller

我有两个 View Controller ,每个包含 UISearchControllerUITableView . 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/

相关文章:

ios - 更改分组 TableView 中的选定单元格

iphone - 如何修复 iOS 中的视频方向问题

ios - 为什么从 iOS 分享到 Instagram 时图像会变大?

ios - 根据将随机更改的 uilabel.text 的长度设置 UILabel 宽度

ios - 让我们缩短 cell.textLabel 的长度

ios - 如何在 iOS 中使用 Twitter API 1.1 获取 Token

ios - MBProgressHud View 自定义在 Swift 3 中不起作用并且不显示?

objective-c - 将 NSCoding 与 Realm 模型对象一起使用

ios - 无法在名称为 'itemCell' 的包中加载 NIB '

iphone - RestKit GET 查询参数