当scopebar被隐藏和显示时,uisearchbar问题

时间:2017-01-23 05:57:00

标签: objective-c uitableview uisearchbar uisegmentedcontrol uisearchcontroller

this issue occurs if i forcefully show the scope bar to render 在呈现搜索控制器的同时,我将showScopeBar属性设置为隐藏或显示范围栏

- (void)willPresentSearchController:(UISearchController *)searchController {
    // do something before the search controller is presented
    NSMutableArray *scopeArray = @[@"All"].mutableCopy;
    UISearchBar *searchBar =_searchController.searchBar;
    if (![labelDepartmentSelection.text isEqualToString:@"Department"]) {
        [scopeArray addObject:@"Department"];
    }
    if (![labelJobSelection.text isEqualToString:@"Job"]) {
        [scopeArray addObject:@"Job"];
    }
    searchBar.scopeButtonTitles = scopeArray;

    searchBar.showsScopeBar = scopeArray.count>1;
    [searchBar layoutIfNeeded];
    NSArray *subviews = searchBar.subviews;
    if([[UIDevice currentDevice].systemVersion floatValue]>=7.0) {
        //Get search bar with scope bar to reappear after search keyboard is dismissed
        UIView *scopeBar = [subviews.firstObject subviews].firstObject;
        [scopeBar setHidden:NO];
        CGRect frame = scopeBar.frame;
        frame.origin.y = frame.origin.y = 64.0;
        scopeBar.frame = frame;
    }
    [searchBar layoutSubviews];

    [searchBar sizeToFit];
    [serviceOptionTableView setContentInset:UIEdgeInsetsMake(scopeArray.count>1?44:0, 0, 0, 0)];

    serviceOptionTableView.tableHeaderView = searchController.searchBar;
}

当我只是隐藏并显示范围栏时,我希望它的范围标题是giet扭曲的 这是

的情况
- (void)willPresentSearchController:(UISearchController *)searchController {
    // do something before the search controller is presented
    NSMutableArray *scopeArray = @\[@"All"\].mutableCopy;
    UISearchBar *searchBar =_searchController.searchBar;
    if (!\[labelDepartmentSelection.text isEqualToString:@"Department"\]) {
        \[scopeArray addObject:@"Department"\];
    }
    if (!\[labelJobSelection.text isEqualToString:@"Job"\]) {
        \[scopeArray addObject:@"Job"\];
    }
    searchBar.scopeButtonTitles = scopeArray;

    searchBar.showsScopeBar = scopeArray.count>1;

    \[serviceOptionTableView setContentInset:UIEdgeInsetsMake(scopeArray.count>1?44:0, 0, 0, 0)\];

}

这是案例2的图像

1 个答案:

答案 0 :(得分:0)

如果删除该行,问题应该自行解决:

searchBar.showsScopeBar = scopeArray.count>1;

出于某种原因,设置showScopeBar属性会产生奇怪的效果。删除它允许默认动画行为没有任何问题。