Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UITableViewController-下拉表视图以显示新的UIView_Ios_Objective C_Uitableview_Uiview_Uiviewcontroller - Fatal编程技术网

Ios UITableViewController-下拉表视图以显示新的UIView

Ios UITableViewController-下拉表视图以显示新的UIView,ios,objective-c,uitableview,uiview,uiviewcontroller,Ios,Objective C,Uitableview,Uiview,Uiviewcontroller,我正在尝试设计一个UITableViewController,这样当用户点击导航栏上的“搜索”按钮时,表视图就会从导航栏中下拉,UIView也会从导航栏中下拉。然后,当用户点击UIView之外的任何位置时,UIView应该缩回,表视图应该返回到其原始位置 目前,我有以下方法作为“搜索”按钮的选择器。注意-self.searchBar是一个自定义UIView子类 有没有更干净/更好的方法来实现这一点?此外,我不知道如何摆脱后,用户点击了搜索菜单的看法。。。我猜我应该调用[self.searchBa

我正在尝试设计一个UITableViewController,这样当用户点击导航栏上的“搜索”按钮时,表视图就会从导航栏中下拉,UIView也会从导航栏中下拉。然后,当用户点击UIView之外的任何位置时,UIView应该缩回,表视图应该返回到其原始位置

目前,我有以下方法作为“搜索”按钮的选择器。注意-self.searchBar是一个自定义UIView子类

有没有更干净/更好的方法来实现这一点?此外,我不知道如何摆脱后,用户点击了搜索菜单的看法。。。我猜我应该调用[self.searchBar removeFromSuperview];但不确定将该行放在哪个委托方法中

谢谢

- (void)_showSearchMenu
{
  CGRect frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height * .25);
  frame.origin.y = CGRectGetMaxY(self.navigationController.navigationBar.frame) - frame.size.height;
  self.searchBar.frame = frame;

  [self.navigationController.navigationBar.superview insertSubview:self.searchBar belowSubview:self.navigationController.navigationBar];

  [UIView animateWithDuration:0.5 animations:^{
    CGRect frame = self.searchBar.frame;
    frame.origin.y = CGRectGetMaxY(self.navigationController.navigationBar.frame);
    self.searchBar.frame = frame;
    self.tableView.contentOffset = CGPointMake(0, -250);
  }];
}
更清楚地说,我正在尝试实现类似于HotelTonight应用程序中的效果(第二个屏幕显示了当您点击右上角的工具栏按钮时发生的情况)

  • 在superview上添加Tap手势
  • 在点击手势动作中,检查搜索栏视图是否可见
  • 如果可见,通过设置高度为零的新框架隐藏下拉视图
  • 您可以通过编程或从Interface Builder添加点击手势,也可以使用其委托方法“shouldReceiveTouch”或任何其他自定义操作。

    • 我认为这是最好的方法,请使用以下学员:

      (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
          return (isOpen) ? 170.0f : 0.0f;
      }
      
      (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
      
          CGFloat height = [self tableView:tableView heightForHeaderInSection:section];
          UIView *vw = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, height)];
          vw.backgroundColor = [UIColor yellowColor];
      
          // add other controls here in your UIView
          // or
          // just add a UIView at top of your UITableView
          // then add other controls to it (if ur using storyboard)
      
          return vw;
      }
      
      (CGFloat)表视图:(UITableView*)表视图 头部高度剖面:(NSInteger)剖面(UIView*) tableView:(UITableView*)tableView 标题部分的视图:(NSInteger)部分

      如何:

    • 创建一个默认值为
      NO
    • 单击“搜索”按钮时,执行以下操作:

      (void) searchButtonTouch:(id)sender { 
          isOpen = (isOpen) ? YES : NO;
          isOpen = !isOpen; 
          [self.urTableView reloadData];
      }
      
    • 现在请各位代表:

      (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
          return (isOpen) ? 170.0f : 0.0f;
      }
      
      (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
      
          CGFloat height = [self tableView:tableView heightForHeaderInSection:section];
          UIView *vw = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, height)];
          vw.backgroundColor = [UIColor yellowColor];
      
          // add other controls here in your UIView
          // or
          // just add a UIView at top of your UITableView
          // then add other controls to it (if ur using storyboard)
      
          return vw;
      }