UISearchController搜索栏位置下降64点

JBl*_*ake 9 objective-c uisearchbar uisearchcontroller

搜索栏正好显示为64点太低:

在此输入图像描述

所有其他帧都完全正确.

编辑: - 这UISearchController是错误的观点origin.y.它设置为64,当它应该为0.如果我添加此方法:

- (void)didPresentSearchController:(UISearchController *)searchController
{
  [super didPresentSearchController:searchController];
  searchController.view.frame = CGRectMake(0, 0, searchController.view.frame.size.width, searchController.view.frame.size.height);

}
Run Code Online (Sandbox Code Playgroud)

然后视图对齐.然而,它的janky因为它跳跃.如果我在willPresentSearchController其中修改框架不起作用,因为控制器必须在其呈现后进行某种布局.

如果我使用SparkInspector,并编辑UISearchBarContainerViewfrom origin 64 的框架(它设置为0,为0),问题就解决了.

这是我的相关配置:

self.searchResultsController = [[GMSearchTableViewController alloc] init];
self.definesPresentationContext = YES;
self.searchController = [[UISearchController alloc] initWithSearchResultsController:self.searchResultsController];
self.searchController.dimsBackgroundDuringPresentation = YES;
self.searchController.hidesNavigationBarDuringPresentation = NO;
self.searchController.searchBar.frame = CGRectMake(0, 0, self.view.frame.size.width, 44);
[self.view addSubview:self.searchController.searchBar];
Run Code Online (Sandbox Code Playgroud)

我没有使用Interface Builder,一切都是在代码中配置的.我很肯定,设置definesPresentationContext是正确的.

VC位于一个常规的UINavigationController,它位于SplitViewController内部(但iPhone上也存在问题).

我觉得我错过了一个简单的配置选项 UINavigationBar

我还有一个不同的控制器,它使用一个更复杂的自定义容器视图控制器模型,并且可以使用.

当我设置

self.definesPresentationContext = NO;
Run Code Online (Sandbox Code Playgroud)

有时候是这样的: 在此输入图像描述

所以现在UISearchBar获取正确,但是表示上下文是错误的,导致UISearchController表视图占据整个视图.

JBl*_*ake 12

在经典时尚中,我找到了一个解决方案(/sf/answers/2100733141/)

这样做的诀窍:

- (UIBarPosition)positionForBar:(id<UIBarPositioning>)bar
{
  if (bar == self.searchController.searchBar) {
    return UIBarPositionTopAttached;
  }
  else { // Handle other cases
    return UIBarPositionAny;
  }
}
Run Code Online (Sandbox Code Playgroud)