【发布时间】:2016-01-29 20:00:46
【问题描述】:
搜索栏正好显示 64 点太低:
所有其他帧都完全正确。
编辑:
- 错误的是UISearchController 的观点origin.y。当它应该为 0 时,它被设置为 64。
如果我添加这个方法:
- (void)didPresentSearchController:(UISearchController *)searchController
{
[super didPresentSearchController:searchController];
searchController.view.frame = CGRectMake(0, 0, searchController.view.frame.size.width, searchController.view.frame.size.height);
}
然后视图对齐。但是,它很笨拙,因为它会跳跃。如果我修改 willPresentSearchController 中的框架,它就不起作用,因为控制器必须在其呈现后进行某种布局。
如果我使用 SparkInspector,并从原点 64 编辑 UISearchBarContainerView 的框架(设置为 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];
我没有使用 Interface Builder,一切都在代码中配置。
我很肯定设置definesPresentationContext 是正确的。
VC 位于一个常规的 UINavigationController 中,它位于 SplitViewController 中(但 iPhone 上也存在问题)。
我觉得我缺少一个关于 UINavigationBar 的简单配置选项
我还有一个不同的控制器,它使用自定义的 Container View Controller 模型,这种模型更复杂,并且可以工作。
当我设置时
self.definesPresentationContext = NO;
所以现在UISearchBar 的位置正确,但是显示上下文错误,导致UISearchController 的表格视图占据了整个视图。
【问题讨论】:
-
感谢您为我的问题提供解决方案。它有帮助。 self.definesPresentationContext = NO;
标签: objective-c uisearchbar uisearchcontroller