Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/99.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 当UISearchBar处于活动状态时,UITableView内容与状态栏重叠_Ios_Uitableview_Uisearchbar_Uisearchdisplaycontroller_Uicontainerview - Fatal编程技术网

Ios 当UISearchBar处于活动状态时,UITableView内容与状态栏重叠

Ios 当UISearchBar处于活动状态时,UITableView内容与状态栏重叠,ios,uitableview,uisearchbar,uisearchdisplaycontroller,uicontainerview,Ios,Uitableview,Uisearchbar,Uisearchdisplaycontroller,Uicontainerview,我有一个带有UISearchBar和UISearchDisplayController的UITableViewController。存在于UINavigationController中UIViewController的容器视图中的。我制作此图像是为了帮助描述结构: 这就是它真正的样子: 当我点击搜索栏时,我必须隐藏导航栏。通常情况下,这会自行发生,但由于我的UITableViewController位于容器视图中,因此我必须自己处理该更改。这就是它看起来的样子,请注意,状态栏是白色的,因为导

我有一个带有UISearchBar和UISearchDisplayController的UITableViewController。存在于UINavigationController中UIViewController的容器视图中的。我制作此图像是为了帮助描述结构:

这就是它真正的样子:

当我点击搜索栏时,我必须隐藏导航栏。通常情况下,这会自行发生,但由于我的UITableViewController位于容器视图中,因此我必须自己处理该更改。这就是它看起来的样子,请注意,状态栏是白色的,因为导航栏是白色的,即使此时它是隐藏的

一旦我开始输入一些搜索文本,结果就会显示出来。如果我向上滚动这些结果,它们会从搜索栏下面经过,但是它们会与状态栏重叠,这很不吸引人

如果不涉及容器视图,则所有这些都会按预期工作,并且表内容会在状态栏下方传递,但是涉及到ContainerView时,表文本和状态栏会发生冲突


如何让文本像普通一样在状态栏下移动?

基本上,这是由于导航栏的扭曲,通常视图控制器通过更正所属视图或子视图的顶部插入(如果它们是(或继承自)UIScrollView)来修复重叠。您有两个选项,一个是将导航栏的透明度设置为否,另一个是将
edgeForExtendedLayout
设置为无或仅保留底部

- (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller {
    self.navigationController.navigationBar.translucent = YES;
}

- (void)searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller {
    self.navigationController.navigationBar.translucent = NO;
}
这些建议仅适用于iOS7,前提是您要在较低的目标上部署,请在设置这些属性之前进行检查。

另一种方法是阅读
--topLayoutGuide
长度,在-
searchDisplayControllerWillBeginSearch
中尝试设置相同长度的topInsets。这样,您仍应保持半透明。

我也有同样的问题:

- (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller
{
    controller.searchBar.searchBarStyle = UISearchBarStyleDefault; // Used to cover UIStatusBar
}

- (void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller
{
    controller.searchBar.searchBarStyle = UISearchBarStyleMinimal; // Used not to show top and bottom separator lines
}

尝试在
TableViewController的
viewDidLoad
中设置
DefinePresentationContext

迅捷的

目标-C

- (void)viewDidLoad {
    [super viewDidLoad];

    self.definesPresentationContext = YES;
}

我已经搜索了几个小时,最后的结果是将这一行放在viewDidLoad中:
self.extendedlayoutincludesopaquebar=YES


问题已解决:)

我有UISearchBar和UISearchDisplayController

在viewdidload中:

self.edgesForExtendedLayout = UIRectEdgeNone;
[searchDisplayController.searchBar setBackgroundImage:[self imageWithColor:ETSBaseColor] forBarPosition:0 barMetrics:UIBarMetricsDefault];
从UIColor获取图像的方法:

- (UIImage *)imageWithColor:(UIColor *)color
{
    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return image;
}

在我的例子中,我不想隐藏UINavigationBar,但我也有类似的问题,包括口吃和其他副作用。其中一个是在UIViewController可见时在UIViewController之间切换后丢失的UISearchBar(我使用SWRevealViewController在UIViewController之间切换)。此问题仅在iPad上发生。结果显示,UISearchBar突然隐藏在UINavigationBar后面。现在,我用UIContainerView中显示的UITableViewController中的以下代码行解决了所有问题:

- (UINavigationController *)navigationController {
    return nil;
}
这些行阻止UISearchDisplayController访问和更改我的UINavigationController。我还将该方法子类化为“MyContainerTableViewController”类,现在将该类用于所有嵌入式UITableViewController


我仍在使用UISearchDisplayController支持iOS 7。

以下是对我有效的方法:

做:

  • 使用UISearchController(不是单独放置的UISearchBar)
  • 如果还没有,请将VC放入UINavigationController中。如果需要,将导航设置为“不显示导航栏”
  • 对UITableView(而不是springs和struts)使用autolayout,并将表的顶部固定到VC视图的顶部
  • 添加此委托方法:
-(UIBAR位置)位置FORBAR:(id)bar{
返回UIBarPositionTopAttached;
}

不要:

  • 摆弄边缘前伸式布局
  • 摆弄扩展布局,包括不透明条
  • 摆弄桌子上的东西

以下黑客技术对我有效:

-(CGFloat)表格视图:(UITableView*)表格视图头部高度部分:(NSInteger)部分
{
返回(self.searchController.isActive&§ion==0)?22.0f:0.0f;
}

我遇到了与OP完全相同的问题,但我没有显示导航栏。这是在导航控制器中,我将其转换为模式弹出窗口。由于我没有显示导航栏,因此设置半透明性并不能解决问题。请尝试使用Edgesforextendedlayout,也可能是
-setAutomaticallyAdjustScrollInsets
不幸的是,这两个选项都没有帮助。我最后使用了导航栏。这真的很有帮助,即使我有一个不同的问题!我的问题是,当搜索栏处于活动状态时,我无法控制状态栏的背景颜色。谢谢你,只是因为有人遇到了这个。确保在containerViewController和searchResultsViewController中添加
self.ExtendedLayoutCludeSopaqueBars=YES
。您也可以在情节提要中的视图控制器的属性检查器中执行此操作(选中“扩展边”->“不透明条”下的)definesPresentationContext=true和self.extendedlayoutincludesopaquebar=true为我修复了它!
- (UINavigationController *)navigationController {
    return nil;
}