OGeek|极客世界-中国程序员成长平台

标题: ios - 点击时更改 TableView 高度(在 xib 中使用自动布局) [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 15:00
标题: ios - 点击时更改 TableView 高度(在 xib 中使用自动布局)

我的 ViewController 在最初加载时是这样的:

initially

当点击显示按钮时,它必须改变如下: When ShowButton tapped

我的代码是:

- (IBAction)showid)sender {
 [self change];
 [tableView reloadData];
}
- (IBAction)closeid)sender { 
 [self change];
 [tableView reloadData];
}

-(void)change{
  //assigning initial bounds to frame-1
  CGRect frame1=CGRectMake(0, _pastProcessTV.frame.origin.y, self.view.bounds.size.width, self.pastProcessTV.bounds.size.height); 
  //assigning new bounds to frame-2
  CGRect frame2=CGRectMake(0, **CGFloat y**,self.view.bounds.size.width,***CGFloat height***);

   if (_showFullButton.isTouchInside) {
          tableView.frame = frame2;
    }
   else{
          tableview.frame = frame1;
   }
}

我尝试了不同的方法。它不起作用。任何人都可以帮我提供 Y 坐标和宽度



Best Answer-推荐答案


当您使用自动布局时,您必须获取 tableview 的 topconstraint 的导出,并且当您想要扩展它时将其值设置为 0

所以它会按预期工作

如果您使用的是 iOS 7

[self.view layoutIfNeeded]是必填项

关于ios - 点击时更改 TableView 高度(在 xib 中使用自动布局),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35746142/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://jike.in/) Powered by Discuz! X3.4