UIUI带有范围栏的 TableView 上的 SearchBar 在其他 UI 项目上自行调整大小

UISearchBar on UITableView with scope bar resizes itself over other UI items

好的,所以我在 UISearchBar 下面有一个 UITableView。上面只是一些 UILables 和 UIButtons,然后是 UINavigationBar。

UISearchBar 启用了范围栏。每当我点击搜索栏时,我都会出现以下奇怪的行为(我已禁用屏幕键盘,但焦点位于 UISearchBar 文本字段中):

通常它看起来像这样:

这真的很令人沮丧,我不知道为什么会这样。有没有人经历过类似的事情并找到了解决方案?

谢谢!

这是一个难题,但这是我能想到的最好的办法。我只是将以下内容放在 viewWillAppear 中,然后手动创建了一个 44px 高的背景图像并将其放在故事板上的 UISearchBar 后面。

-(void)viewWillAppear:(BOOL)animated
{
    [self.searchBar sizeToFit];
    for (UIView *subview in self.view.subviews) {

        for(UIView *subView2 in subview.subviews){

            for(UIView *subView3 in subView2.subviews){
                if ([[[subView3  class] description] isEqualToString:@"UISearchBarBackground"]) {
                   [subView3 removeFromSuperview];
                   break;
                }
            }
        }
    }
}