解决ios10以下UISearchController偏移的坑

解决ios10以下UISearchController偏移的坑


//解决搜索框偏移问题

self.definesPresentationContext = YES;

self.automaticallyAdjustsScrollViewInsets = NO;

//searchBar

self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];

self.searchController.searchBar.frame = CGRectMake(0, 0, 0, 44);

self.searchController.dimsBackgroundDuringPresentation = NO;

self.searchController.hidesNavigationBarDuringPresentation = YES;

self.searchController.searchBar.delegate = self;

[self.searchController.searchBar sizeToFit];

self.searchController.searchResultsUpdater = self;

self.searchController.delegate = self;

self.searchController.searchBar.returnKeyType = UIReturnKeyDone;

self.tableView.tableHeaderView = _searchController.searchBar;

//下面代码解决搜索之后tableview不移动问题

- (void)didPresentSearchController:(UISearchController *)searchController {

[UIView animateWithDuration:0.3 animations:^{

[self.tableView mas_updateConstraints:^(MASConstraintMaker *make) {

make.top.mas_equalTo(self.view).offset(20);

}];

[self.tableView layoutIfNeeded];//强制绘制

}];

}

- (void)willDismissSearchController:(UISearchController *)searchController {

[UIView animateWithDuration:0.3 animations:^{

[self.tableView mas_updateConstraints:^(MASConstraintMaker *make) {

make.top.mas_equalTo(self.view).offset(64);

}];

[self.tableView layoutIfNeeded];//强制绘制

}];

}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容