UISearchController 在编辑开始时更改宽度

UISearchController change width when editing starts

我将在 KGModal 中展示我的 tableViewController。 在我的 viewDidLoad 中,我添加了以下几个属性来管理 tableView:

[self setupSearchController];
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
self.tableView.tableHeaderView = self.searchController.searchBar;
self.edgesForExtendedLayout = UIRectEdgeNone;
self.definesPresentationContext = NO;
self.view.clipsToBounds = YES;

setupSearchController

-(void)setupSearchController
{
    self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
    self.searchController.searchResultsUpdater = self;
    self.searchController.dimsBackgroundDuringPresentation = NO;
    self.searchController.hidesNavigationBarDuringPresentation = NO;
    //  self.searchController.searchBar.scopeButtonTitles = @[NSLocalizedString(@"ScopeButtonCountry",@"Country"), NSLocalizedString(@"ScopeButtonCapital",@"Capital")];
   // self.searchController.searchBar.clipsToBounds = YES;
    self.searchController.searchBar.delegate = self;
}

现在,当我 运行 应用程序时,它显示 searchController 为



Which is fine and exactly what I'm looking for. But as soon as it became the first responder this happens:



通过取消它使它成为回到第一张图片的位置。我的问题是如何让它留在 KGModal 的框架内。我在哪里称它为

CPTSearchTableViewController *ivc = [self.storyboard instantiateViewControllerWithIdentifier:@"CPTSearchTVC"];
    ivc.view.frame = CGRectMake(0, 0, CGRectGetWidth([[UIScreen mainScreen] bounds]) - 40, CGRectGetHeight([[UIScreen mainScreen] bounds]) - 80);
    [[KGModal sharedInstance] setCloseButtonType:KGModalCloseButtonTypeRight];
    [[KGModal sharedInstance] showWithContentViewController:ivc andAnimated:YES];
    [[KGModal sharedInstance] setTapOutsideToDismiss:YES];
    [[KGModal sharedInstance] setModalBackgroundColor:[UIColor clearColor]];
    [[KGModal sharedInstance] setBackgroundDisplayStyle:KGModalBackgroundDisplayStyleSolid];


更新
通过遵循给定的解决方案之一 here 我已经能够将其保持在高度范围内而不是视图宽度范围内。
我刚刚将 VIewDidLoad 中的代码更新为

 [self setupSearchController];
    self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    self.tableView.tableHeaderView = self.searchController.searchBar;
    self.edgesForExtendedLayout = UIRectEdgeNone;
    self.definesPresentationContext = YES;
    self.extendedLayoutIncludesOpaqueBars = YES;

换框检查一次

更改此行

//[[KGModal sharedInstance] showWithContentViewController:ivc andAnimated:YES];

到这个

  [[KGModal sharedInstance] showWithContentView:ivc.view andAnimated:YES];

更新答案

-(void)showTableView
{
SampleTableViewController *ivc = [self.storyboard instantiateViewControllerWithIdentifier:@"SampleVC"];
//ivc.delegate = self;
ivc.view.frame = CGRectMake(0, 0, CGRectGetWidth([[UIScreen mainScreen] bounds]) - 40, CGRectGetHeight([[UIScreen mainScreen] bounds]) - 80);
[[KGModal sharedInstance] setCloseButtonType:KGModalCloseButtonTypeRight];
 [[KGModal sharedInstance] setTapOutsideToDismiss:NO];
 //[[KGModal sharedInstance] showWithContentViewController:ivc andAnimated:YES];
 [[KGModal sharedInstance] showWithContentView:ivc.view andAnimated:YES];
[[KGModal sharedInstance] setTapOutsideToDismiss:YES];
//    [[KGModal sharedInstance] setModalBackgroundColor:[UIColor clearColor]];
[[KGModal sharedInstance] setBackgroundDisplayStyle:KGModalBackgroundDisplayStyleSolid];
}