【问题标题】:UISearchController change width when editing starts编辑开始时 UISearchController 更改宽度
【发布时间】:2016-10-04 14:58:05
【问题描述】:

我将在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 为



这很好,正是我正在寻找的。但是,一旦它成为第一响应者,就会发生这种情况:



通过取消它使它回到它在第一张图片中的位置。我的问题是如何让它留在 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;

【问题讨论】:

  • stackoverflow.com/questions/26222671/…你试过这些答案吗?
  • @HannahLouisaCarney 查看我更新的问题
  • 你能把你的项目贴在这里
  • @Anbu.Karthik 我该怎么做?
  • 将您的项目附加到下拉框中并提供链接

标签: ios objective-c uitableview uisearchcontroller


【解决方案1】:

更换框架并检查一次

改变这一行

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

【讨论】:

  • 我在setupSearchController 中添加了这个,但没有用!昨天当我将self.definesPresentationContextNO 更改为YES 时,问题的更新部分发生了。这意味着 Y 保持不变,但 X 发生变化。
  • @TalhaCh - 是的,我也这么认为,问题是当你正确地展示键盘时,如果你附上项目,我会检查并告诉你
  • @TalhaCh - 下载成功
  • @TalhaCh - 删除此行 [[searchController searchBar] sizeToFit]; 并尝试一次
  • @TalhaCh - 检查更新的答案,错误已修复
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-14
  • 1970-01-01
  • 2014-09-07
  • 1970-01-01
  • 1970-01-01
  • 2010-12-11
  • 1970-01-01
相关资源
最近更新 更多