单击时搜索栏正在更改位置

Search Bar is changing position when clicked

我已经在 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];
}

提前致谢。

这也发生在我身上, 只需将其设置为 NO.

self.definesPresentationContext = NO

检查这个:

对于 swift 4.x,这对我有用

self.edgesForExtendedLayout = .bottom