UISearchController中的searchBar in tableHeaderView动画出屏幕 [英] UISearchController searchBar in tableHeaderView animating out of the screen

查看:60
本文介绍了UISearchController中的searchBar in tableHeaderView动画出屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UISearchController ,带有 UITableViewController 作为 searchResultsController ,此 searchController UISearchBar 设置为 tableHeaderView tableView 的c $ c>。正如预期的那样,几乎所有事情都运作良好。但是在 UISearchBar 的动画中(当我点击searchBar并且 UINavigationBar 隐藏并且searchBar转到顶部,如在 UISearchDisplayController 中)我有一个奇怪的行为。它不会移动到 UINavigationBar (y:0)的位置,而是跳出屏幕而不是启动显示取消按钮的动画。我尝试将我的实例化代码移动到 viewDidLoad 而不是 init ,事情就是一样的。我认为问题的中心位于 searchResultsController 的视图框架中,但我不确定(我尝试设置框架,但没有成功) 。我正在做的一切都是纯粹的代码。

I have a UISearchController with a UITableViewController as a searchResultsController, the UISearchBar of this searchController is set to be in the tableHeaderView of my current tableView displayed in my root ViewController. Almost everything is working well, as expected. But in the animation of the UISearchBar (When i click on the searchBar and the UINavigationBar hides and the searchBar goes to the top, as in the UISearchDisplayController) i have a strange behavior. Instead of moving to the position of the UINavigationBar (y: 0), it jumps out of the screen and than starts the animation that shows the cancel button. I tried moving my instantiate code to the viewDidLoad instead of init, and the things are just the same. I think that the center of the problem is in the frame of the searchResultsController's view, but i'm not sure about that(I tried setting the frame, without success). Everything that i am doing is in pure code.

以下是代码的相关部分:

Here is the relevant part of the code:

- (void) viewDidLoad { 
    [super viewDidLoad];

    // search controller setup
    self.searchController = [[UISearchController alloc] initWithSearchResultsController:self.searchResultsController];
    self.searchController.delegate = self;
    self.searchController.searchResultsUpdater = self;
    self.searchController.searchBar.delegate = self;

    [self.searchController.searchBar sizeToFit];
    self.tableView.tableHeaderView = self.searchController.searchBar;

    self.searchController.definesPresentationContext = YES;
}

我对 searchResultsController的延迟加载

- (UITableViewController *)searchResultsController {
    if (_searchResultsController == nil) {
        _searchResultsController = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];
        _searchResultsController.tableView.delegate = self;
        _searchResultsController.tableView.dataSource = self;
    }
    return _searchResultsController;
}

我从apple下载了示例代码,但他们使用的是storyBoards和a对于UITableViewCell的xib,SearchController在项目中完美运行。有没有人有同样的问题?我怎样才能解决这个问题?任何解决方案或建议将不胜感激。

I've downloaded the sample code from apple, but they use storyBoards and a xib for UITableViewCell, the SearchController works perfectly in the project. Does anyone had the same problem? How can i fix this? Any solutions or suggestions would be appreciated.

感谢您的关注。

推荐答案

添加

self.extendedLayoutIncludesOpaqueBars = YES;

viewDidLoad 方法

这篇关于UISearchController中的searchBar in tableHeaderView动画出屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆