iOS 7 UISearchBarDisplayController重叠搜索栏并错放导航控制器

时间:2014-07-30 13:03:20

标签: ios objective-c uisearchbar uisearchdisplaycontroller

我找到了很多解决方案来避免这个问题,遗憾的是它们都没有对我有用。 单击searchBar时,这是问题的屏幕截图。如您所见,它也会向上推导航控制器。 enter image description here

现在这就是我的尝试。

解决方案1:

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

}

Sloution 2:

-(void)viewDidAppear:(BOOL)animated{
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
    CGRect statusBarFrame =  [[UIApplication sharedApplication] statusBarFrame];
    [self.cityTableView setFrame:CGRectMake(self.cityTableView.frame.origin.x, self.cityTableView.frame.origin.y+statusBarFrame.size.height, self.cityTableView.frame.size.width, self.cityTableView.frame.size.height)];

   }
}

解决方案3:

 - (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller {
if (IS_OS_7_OR_LATER) {
    CGRect statusBarFrame =  [[UIApplication sharedApplication] statusBarFrame];
    CGRect frame = self.citySearchBar.frame;
    frame.origin.y += statusBarFrame.size.height;
    self.citySearchBar.frame = frame;
}
}

- (void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller {
if (IS_OS_7_OR_LATER) {
    CGRect statusBarFrame =  [[UIApplication sharedApplication] statusBarFrame];
    CGRect frame = self.citySearchBar.frame;
    frame.origin.y -= statusBarFrame.size.height;
    self.citySearchBar.frame = frame;
}
}

解决方案4:

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

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

解决方案5:在Autolayout的情况下可能有用。但我没有使用它。

 - (void) viewDidLayoutSubviews
 {
    if(floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1)
   {
      CGRect viewBounds = self.view.bounds;
      CGFloat topBarOffset = self.topLayoutGuide.length;
      viewBounds.origin.y = topBarOffset * -1;
      self.view.bounds = viewBounds;
   }
 }

那我在这里错过了什么?

0 个答案:

没有答案