UISearchController搜索栏位置下降64点 [英] UISearchController Search Bar Position Drops 64 points

查看:382
本文介绍了UISearchController搜索栏位置下降64点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

搜索栏显示的准确度太低了64点:

The search bar is appearing exactly 64 points too low:

所有其他帧都完全正确.

All of the other frames are exactly correct.

-错误的origin.yUISearchController的视图.当它应该为0时,它将设置为64. 如果我添加此方法:

- It's the UISearchController's view that is getting the wrong origin.y. It gets set to 64, when it should be 0. If I add this method:

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

}

然后将视图对齐.但是,由于它会跳动,所以它很简陋.如果我在willPresentSearchController中修改框架,则该框架将无法正常工作,因为控制器在呈现后必须进行某种布局.

Then the views align. However, its janky because it jumps. If I modify the frame in willPresentSearchController it does not work, as the controller must be doing some sort of layout after its presented.

如果我使用SparkInspector,并从原点64(将其设置为0)编辑UISearchBarContainerView的框架,则问题得以解决.

If I use SparkInspector, and edit the frame of the UISearchBarContainerView from origin 64 (what it gets set at, to 0), the problem is resolved.

这是我的相关配置:

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];

我没有使用Interface Builder,所有内容都在代码中进行了配置. 我很肯定设置definesPresentationContext是正确的.

I'm not using Interface Builder, everything is configured in code. I'm positive that setting definesPresentationContext is correct.

VC位于常规的UINavigationController中,该常规文件位于SplitViewController内(但iPhone上也存在问题).

The VC sits in a regular UINavigationController, which is inside a SplitViewController (but problem exists on iPhone as well).

我觉得我缺少关于UINavigationBar

我还有一个控制器,它使用自定义的容器视图控制器"模型,该模型更为复杂,并且可以正常工作.

I also have a different controller that uses a custom Container View Controller model, which is more complex, and that one works.

设置后

self.definesPresentationContext = NO;

发生这种情况:

因此,现在UISearchBar的位置正确,但是表示上下文错误,导致UISearchController的表视图占据了整个视图.

So now the UISearchBar gets positioned correctly, but the presentation context is wrong, causing the UISearchController's table view to occupy the full view.

推荐答案

以经典的方式,我找到了一个解决方案( https ://stackoverflow.com/a/30010473/579217 )

Well in classic fashion, I've found a solution (https://stackoverflow.com/a/30010473/579217)

这可以解决问题:

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

这篇关于UISearchController搜索栏位置下降64点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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