本文介绍了SearchDisplayController SearchBar重叠导航栏并调整自身的大小IOS7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序有一个tableview控制器,显示为表单。

My app has a tableview controller that is presented as a form sheet.

在tableviewcontoller的顶部有一个UView,在UIView里面有一个导航栏和一个搜索栏。

On top portion of tableviewcontoller there is a UView and inside of that UIView there is a navigation bar and a searchbar.

一切都运行良好的旧版IOS,但在用户点击搜索栏的IOS7中,一切都很糟糕。

Everything works fine older version of IOS but in IOS7 when user taps searchbar everything is messes up.

正常:

当用户开始输入时:

When User starts to type:

搜索结束后:

After seach ends:

in.h

UITableViewController<UITextFieldDelegate,UISearchDisplayDelegate,UISearchBarDelegate>
@property (nonatomic,weak) IBOutlet UINavigationBar *topBar;

尝试了一些事情,但代码似乎没有改变任何东西,当它输入一个断点进入委托方法时虽然

Tried few things but code doesnt seem to be changing anything, when put a breakpoint it enters to delegate methods though

in.m

//-(void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller {
//    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
//        CGRect statusBarFrame =  self.topBar.frame;
//        [UIView animateWithDuration:0.25 animations:^{
//            for (UIView *subview in self.tableView.subviews)
//                subview.transform = CGAffineTransformMakeTranslation(0, statusBarFrame.size.height+50);
//        }];
//    }
//}
//
//-(void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller {
//    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
//        [UIView animateWithDuration:0.25 animations:^{
//            for (UIView *subview in self.tableView.subviews)
//                subview.transform = CGAffineTransformIdentity;
//        }];
//    }
//}

- (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller {
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
        CGRect frame = self.searchDisplayController.searchBar.frame;
        frame.origin.y += self.topBar.frame.size.height;
         self.searchDisplayController.searchBar.frame = frame;
    }
}

- (void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller {
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
        CGRect statusBarFrame = self.topBar.frame;
        CGRect frame =  self.searchDisplayController.searchBar.frame;
        frame.origin.y -= statusBarFrame.size.height;
         self.searchDisplayController.searchBar.frame= frame;
    }
}


#Additional Info
- (void)viewDidLoad
{
    [super viewDidLoad];
      if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
    {
        //self.searchDisplayController.searchBar.searchBarStyle= UISearchBarStyleProminent;
        self.edgesForExtendedLayout = UIRectEdgeNone;
        //self.edgesForExtendedLayout = UIRectEdgeLeft | UIRectEdgeBottom | UIRectEdgeRight;
    }
}

根据断点,帧位置和大小是正确的,但它们不会改变 self.searchDisplayController.searchBar.frame at all

According to break points frame position and sizes are correct but they dont change self.searchDisplayController.searchBar.frame at all

我也试过

-(void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller {
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
        [self.topBar setHidden:YES];

    }
}

-(void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller {
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
        [self.searchDisplayController.searchBar removeFromSuperview];
        CGRect frame = self.searchDisplayController.searchBar.frame;
        frame.origin.y += self.topBar.frame.size.height;
        self.searchDisplayController.searchBar.frame = frame;
        [self.topView addSubview:self.searchDisplayController.searchBar];
        [self.topView bringSubviewToFront:self.topBar];

        [self.topBar setHidden:NO];
    }
}

如何解决此问题?

推荐答案

我有类似的问题,我认为searchDisplayController将searchBar大小扩展为full tableHeaderView大小(我真的不知道为什么呢)这样做)。 tableHeaderView中有搜索栏和一个自定义工具栏(均为44px高度)。

I had a similar problem, I think searchDisplayController expands searchBar size to full tableHeaderView size (I really don't know why it doing this). I had searchbar and one custom toolbar (both 44px height) in tableHeaderView.

我的工作方式是:

- (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller {
    self.tableView.tableHeaderView.frame = CGRectMake(0, 0, self.tableView.bounds.size.width, 44);
}

- (void)searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller {
    self.tableView.tableHeaderView.frame = CGRectMake(0, 0, self.tableView.bounds.size.width, 88);
}

所以我只是在输入搜索和设置时将tableHeaderView设置为单个UISearchBar的大小当所有动画完成时它会回来。这解决了我的问题。甚至动画仍然有效(但它们不在childViewController中。不知道为什么)

So I just setting tableHeaderView to the size of single UISearchBar when entering search and set it back when all animations complete. This solved my problem. Even animations still work (but they does not in the childViewController. No idea why)

这篇关于SearchDisplayController SearchBar重叠导航栏并调整自身的大小IOS7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-09 22:47