简体   繁体   English

iOS 7 + iPad:UISearchBar导致导航栏内容与状态栏混合

[英]iOS 7 + iPad: UISearchBar causes navigation bar content to be mixed with status bar

This happens only on iPad: 这只发生在iPad上:

  • Put a simple UISearchBar in a UIViewController with a UINavigationController 将一个简单的UISearchBar放在带有UINavigationControllerUIViewController
  • [optional] Set bar tint color: self.navigationController.navigationBar.barTintColor = [UIColor clearColor]; [可选]设置条纹色调: self.navigationController.navigationBar.barTintColor = [UIColor clearColor];
  • Run the app. 运行应用程序。
  • Tap on search bar (triggers animation) 点按搜索栏(触发动画)
  • Now status bar is mixed with the top of the navigation bar content (ie title, buttons) 现在状态栏与导航栏内容的顶部混合(即标题,按钮)

Before tap: 点按之前: 在此输入图像描述

After tapping the search bar: 点击搜索栏后: 在此输入图像描述

The problem happens with any color, but using [UIColor clearColor] as in the photos attached makes it easier to see the issue. 任何颜色都会出现问题,但在附带的照片中使用[UIColor clearColor]可以更容易地看到问题。

Any solutions will be great, although I prefer something more elegant than hiding the navigation bar title and buttons each time. 任何解决方案都会很棒,虽然我更喜欢比每次隐藏导航栏标题和按钮更优雅的东西。

EDIT 编辑

This bug happens only when using the following code in viewdidLoad : 只有在viewdidLoad使用以下代码时才会发生此错误:

if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
    self.edgesForExtendedLayout = UIRectEdgeNone;

I think I got once the same issue. 我想我曾经遇到过同样的问题。 If you are using storyboards, check please that all the outlets are set: 如果您使用的是故事板,请检查所有插座是否已设置:

在此输入图像描述

That fixed the animation... 修复动画...

A workaround I used eventually: 我最终使用的解决方法:

- (BOOL)prefersStatusBarHidden
{
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
        return self.searchDisplayController.isActive;

    return NO;
}

This way when user searches it hides the status bar. 这种方式,当用户搜索它时隐藏状态栏。

有完全相同的问题,修复结果是一行:

self.searchDisplayController.searchBar.translucent = NO;

I had the same problem. 我有同样的问题。 The following code worked: 以下代码有效:

self.edgesForExtendedLayout = UIRectEdgeTop;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM