首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >点击时更改TableView高度(使用xib中的自动布局)

点击时更改TableView高度(使用xib中的自动布局)
EN

Stack Overflow用户
提问于 2016-03-02 19:38:47
回答 3查看 146关注 0票数 2

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

当点击显示按钮时,它必须像这样改变:

我的代码是:

代码语言:javascript
复制
- (IBAction)show:(id)sender {
 [self change];
 [tableView reloadData];
}
- (IBAction)close:(id)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;
   }
}

我试过不同的方法。这不是working.can,谁能帮我给出Y坐标和宽度

EN

回答 3

Stack Overflow用户

发布于 2016-03-02 19:41:19

当你使用autolayout时,你必须从表视图的topconstraint中取出,当你想要展开它时,将它的值设置为0

因此,它将按预期工作

如果使用的是iOS 7

[self.view layoutIfNeeded]是不可抗拒的

票数 1
EN

Stack Overflow用户

发布于 2016-04-11 16:09:01

如果你必须使用自动排版,请尝试这样的图片

Make Layout Constraint Property

并尝试以下代码

代码语言:javascript
复制
#import "ViewController.h"

@interface ViewController ()
{
    CGFloat oldtableViewTopValue;
}

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *tableViewTopLC;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

- (void) viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    [self.view setNeedsLayout];
    [self.view layoutIfNeeded];

    oldtableViewTopValue = _tableViewTopLC.constant;
}

- (IBAction)showBtnAction:(id)sender
{
    [UIView animateWithDuration:0.5f animations:^{

        _tableViewTopLC.constant = (_tableViewTopLC.constant==oldtableViewTopValue ? 0 : oldtableViewTopValue);

        [self.view setNeedsLayout];
        [self.view layoutIfNeeded];
    }];
}
@end
票数 1
EN

Stack Overflow用户

发布于 2016-03-02 20:11:22

请关闭情节提要中的自动布局

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35746142

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档