我已经在Objective C中为iOS设备编写了searchBar代码,它在iPhone上运行良好但是在iPad上它正在改变它的x值,因为取消按钮也隐藏了。
最初搜索栏看起来像:
点击搜索栏后:
是否有人面对这个问题并在此向我提出建议?
以下是代码:
self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.searchController.searchBar.delegate = self;
self.searchController.searchResultsUpdater = self;
self.searchController.dimsBackgroundDuringPresentation = NO;
followTableView.tableHeaderView = self.searchController.searchBar;
UISearchBar.appearance.tintColor = [UIColor whiteColor]; //Cancel button color
[self.searchController.searchBar sizeToFit];
tapGesture = [[UITapGestureRecognizer alloc]init];
[tapGesture addTarget:self action:@selector(tapGestureBtnAction:)];
self.searchController.searchBar.barTintColor = searchBarColor;
-(IBAction)tapGestureBtnAction:(id)sender
{
[_searchController.searchBar resignFirstResponder];
[self.view removeGestureRecognizer:tapGesture];
}
提前致谢。
答案 0 :(得分:2)
这也发生在我身上, 只需将此设置为NO。
self.definesPresentationContext = NO
答案 1 :(得分:0)
对于Swift 4.x,这对我有用
self.edgesForExtendedLayout = .bottom