UISearchController - 空格隐藏状态栏

时间:2016-04-22 01:11:29

标签: ios uisearchbar statusbar uisearchcontroller

我正在使用UISearchController,它运行正常。但是它会在搜索栏上方留下一个空白区域(当它被聚焦时),它会部分隐藏状态栏。 This espace

我已经尝试设置self.edgesForExtendedLayout = UIRectEdgeNoneself.navigationController.extendedLayoutIncludesOpaqueBars = YES,但空间仍然存在。我尝试设置self.definesPresentationContext = YES;,但它生成了searchBar获取状态栏位置like this

我正在UIViewController中嵌入UINavigationController。这是我现在正在实施的setUp:

@interface DirectoryViewController :  UIViewController <UITableViewDataSource , UITableViewDelegate ,UISearchBarDelegate, UISearchControllerDelegate, UISearchResultsUpdating>

@property (strong, nonatomic) NSMutableArray *personsArray;
@property (nonatomic, strong) UISearchController *searchController;
@property (nonatomic, strong) NSMutableArray *searchResults;


@implementation DirectoryViewController

- (void)viewDidLoad {
    [super viewDidLoad];
UINavigationController *searchResultsController = [[self storyboard] instantiateViewControllerWithIdentifier:@"TableSearchResultsNavController"];

    // Our instance of UISearchController will use searchResults
    self.searchController = [[UISearchController alloc] initWithSearchResultsController:searchResultsController];

    // The searchcontroller's searchResultsUpdater property will contain our tableView.
    self.searchController.searchResultsUpdater = self;
    self.searchController.delegate = self;
    self.searchController.searchBar.delegate = self;

    //Cancel button tint
    _searchController.searchBar.tintColor = [UIColor whiteColor];
    [self.searchController.searchBar setBackgroundImage:[UIImage imageNamed:@"navBar"]
                                                forBarPosition:0
                                                    barMetrics:UIBarMetricsDefault];

    if ([self respondsToSelector:@selector(edgesForExtendedLayout)]) { /// iOS 7 or above
        self.edgesForExtendedLayout = UIRectEdgeNone;
    }

    self.navigationController.extendedLayoutIncludesOpaqueBars = YES;

}

我感谢任何帮助。感谢

1 个答案:

答案 0 :(得分:0)

我在This answer找到了解决方案。

更改tableInsets:

    self.directoryTable.contentInset = UIEdgeInsetsMake(-10, 0, 0, 0);

当searchController成为FirstFirstResponder

    self.directoryTable.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);

搜索栏操作完成时。