我已经在Objective C中为iOS设备编写了搜索栏的代码,它在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];
}
提前致谢。
这也发生在我身上,只是把它设置为NO。
self.definesPresentationContext = NO
对于swift 4.x,这对我有用
self.edgesForExtendedLayout = .bottom