我正在使用 UISearchController
和 UITableView
。 When a cell in the UITableView
is selected, I'm adding a black UIView
above the whole screen with some subviews on it.当 UISearchController
处于非事件状态时,它工作得很好。但是当它处于事件状态时,UISearchBar
会显示在我的黑色 View 上方。
self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.searchController.searchResultsUpdater = self;
self.searchController.dimsBackgroundDuringPresentation = NO;
self.searchController.searchBar.scopeButtonTitles = [NSArray array];
self.searchController.searchBar.delegate = self;
self.searchController.hidesNavigationBarDuringPresentation = NO;
self.searchController.searchBar.backgroundImage = [self imageWithColor:[MySingleton shared].barTintColor];
[self.searchController.searchBar sizeToFit];
[self.view addSubview:self.searchController.searchBar];
myView = [[UIView alloc] initWithFrame:CGRectMake(0, -64, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
myView.backgroundColor = [UIColor blackColor];
myView.layer.opacity = 0.9;
[self.view addSubview:myView];
我试过在放置 View 之前使其处于非事件状态,
self.searchController.active = NO;
并将 myView 添加到导航 Controller 的 View 中
[self.navigationController.view addSubview:myView];
仍然没有运气。有什么想法吗?
最佳答案
有一种方法允许您在 View 层次结构中的另一个 View 之上插入一个 View ,该方法称为:- insertSubview:aboveSubview:
。以下是您可以如何使用它:
if (self.searchController.searchBar)
[self.view insertSubview:myView aboveSubview:self.searchController.searchBar];
else
[self.view addSubview:myView];
关于ios - 如何以编程方式关闭 UISearchBar?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32382167/