搜索栏在单击时更改位置

问题描述 投票:0回答:2

我已经在Objective C中为iOS设备编写了搜索栏的代码,它在iPhone上运行良好但是在iPad上它正在改变它的x值,因为取消按钮也隐藏了。

最初搜索栏看起来像:

enter image description here

点击搜索栏后:

enter image description here

有没有人面对这个问题,并在此向我提出建议?

这是代码:

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];
}

提前致谢。

ios objective-c ipad uisearchbar uisearchcontroller
2个回答
2
投票

这也发生在我身上,只是把它设置为NO。

self.definesPresentationContext = NO

检查一下:UISearchController Search Bar Position Drops 64 points


0
投票

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

self.edgesForExtendedLayout = .bottom
© www.soinside.com 2019 - 2024. All rights reserved.