UISearchBar后面可见的范围栏

3
我在iOS9中遇到了奇怪的行为,当ViewController第一次出现时,范围栏会显示在UISearchBar的后面:

Bug

按下“搜索”按钮后,UISearchBar的行为符合预期(UISearchBar移动到顶部,范围栏在下方)。在完成搜索或点击取消后,它返回到我从一开始就想要的状态:

Subsequent correct look

在viewDidLoad方法中,我初始化UISearchController如下:
    self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
    self.searchController.searchResultsUpdater = self;
    self.searchController.dimsBackgroundDuringPresentation = NO;
    self.searchController.searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
    self.searchController.searchBar.autocapitalizationType = UITextAutocapitalizationTypeNone;
    [self.searchController.searchBar sizeToFit];

    self.definesPresentationContext = YES;
    self.tableView.tableHeaderView = self.searchController.searchBar;

    self.searchController.searchBar.delegate = self;
    self.searchController.searchBar.scopeButtonTitles = @[[self titleForScopeButton:ScopeButtonIdNameDesc],
                                                          [self titleForScopeButton:ScopeButtonIP]];

有什么想法吗?
1个回答

0

我有一段时间没有在那个应用程序上工作了,忘记了我在appDelegate的didFinishLaunchingWithOptions中设置了UISearchBar的整体外观。

[[UISearchBar appearance] setSearchBarStyle:UISearchBarStyleMinimal];
[[UISearchBar appearance] setBackgroundColor:[PCConstantsGUI tintColor]];
[[UISearchBar appearance] setTintColor:[PCConstantsGUI tintColor]];

导致渲染问题的罪魁祸首是“UISearchBarStyleMinimal”,在我不得不用UISearchController替换已弃用的UISearchDisplayController之前,它看起来很漂亮。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接