【问题标题】:UISearchBar animates incorrectly underneath the navigationBarUISearchBar 在导航栏下方的动画不正确
【发布时间】:2016-03-20 11:47:10
【问题描述】:

我有两个视图控制器,每个控制器包含UISearchController 和一个UITableViewviewDidLoad 中的代码是:

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;

第一个视图控制器是rootViewController,它可以完美运行,没有任何问题。第二个视图控制器正在通过基于段选择的导航控制器推送。

[self.navigationController pushViewController:self.vc];

第二个视图控制器只有一个问题。当我点击searchBar 时,它会动画到顶部并进入导航栏下方,而第一个动画会在其位置动画并且不会上升。

谁能告诉我如何禁用这个动画? 我想在搜索时将searchBar 保留在同一位置。两个视图控制器的实现完全相同。为什么每个人的行为不同?

谢谢,

【问题讨论】:

  • 我不明白这个the second view controller is being pushed via the navigation controller based on segment selection.
  • 我的意思是有一个分段控制器。当我点击第二个段时,它会导航到第二个 viewController。

标签: ios objective-c uitableview uisearchcontroller


【解决方案1】:

hidesNavigationBarDuringPresentation boolean on the UISearchController 设置为NO

self.searchController.hidesNavigationBarDuringPresentation = NO;

或者试试this answer,听起来和你想做的很相似。但你可能想调整这条线:

[super setActive: visible animated: animated]; // instead of passing animated, pass NO

【讨论】:

  • 我尝试设置 hidesNavigationBarDuringPresentation,但它也不起作用。并且 UISearchController 没有 setActive 方法的动画参数。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多