简体   繁体   中英

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

This happens only on iPad:

  • Put a simple UISearchBar in a UIViewController with a UINavigationController
  • [optional] Set bar tint color: 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.

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 :

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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