我正在使用iOS 11中引入的新API,将UISearchController作为导航栏的一部分使用。在我的ViewController的viewDidLoad方法中,我以以下方式使用它:
- (void)viewDidLoad {
[super viewDidLoad];
[_table setDataSource:self];
[_table setDelegate:self];
searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
[self.navigationItem setSearchController:searchController];
[self.navigationItem setHidesSearchBarWhenScrolling:NO];
[searchController.searchBar setBackgroundColor:[UIColor greenColor]];
}
然而,搜索文本字段在搜索栏内呈错误位置呈现。请查看以下截图。 我检查了视图层次结构,并发现搜索栏中的UISearchBarTextField对象(无法直接访问开发人员)具有frame.y值为1,这可能是导致此问题的原因。我已在iOS 11 beta 10和iOS 11 GM上进行了测试。
这是一个已知的问题吗?是否有任何修复方法?还是我在我的端上做错了什么?
任何帮助将不胜感激(:)