【问题标题】:iOS UISearchController doesn't span fullyiOS UISearchController 没有完全跨越
【发布时间】:2018-06-04 20:24:45
【问题描述】:

在一些主要是 6s 的设备类型中,UISearchController 没有完全跨越。

    //Init search controller
    self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
    UISearchBar *searchBar = self.searchController.searchBar;
    searchBar.frame = self.searchBarHolder.bounds;
    self.searchController.searchResultsUpdater = self;
    self.searchController.delegate= self;
    self.searchController.searchBar.delegate=self;
    self.searchController.dimsBackgroundDuringPresentation = NO;
    self.searchController.hidesNavigationBarDuringPresentation = NO;

    [self.searchBarHolder addSubview:searchBar];
    [self.searchBarHolder layoutIfNeeded];
    [searchBar sizeToFit];

searchBarHolder 在情节提要中设置,约束为trailing-0, top-0, leading-0, height - 45

这会产生以下结果:

一旦点击搜索栏,它就会出现becomeFirstResponder,然后,它就会正确显示。

我不知道为什么它一开始会这样显示。

这个UIViewController 嵌入在UINavigationCOntroller 中,并且它作为选项卡项之一嵌入在UITabBarController 中。

【问题讨论】:

  • “取消”按钮是否出现过?
  • 是的,点击搜索栏时会出现。

标签: ios objective-c uisearchcontroller


【解决方案1】:

替换此行

searchBar.frame = self.searchBarHolder.bounds;

有了这个

CGRect rect = self.searchBarHolder.bounds;
rect.size.width = [UIScreen mainScreen].bounds.size.width;
searchBar.frame = rect

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-19
    • 2012-02-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多