在没有自动布局的情况下增加UIView的高度

时间:2016-07-29 07:44:07

标签: ios objective-c uiview

我需要创建一个" old"样式UIView,没有AutoLayout和约束。在我看来,有一个表视图,它使用自动布局和另一个视图计算它的大小。不幸的是,看来,视图本身并不能提供我需要的高度。这就是我创建UIView的方式:

// View 1 - Calendar View

FSCalendar *calendar = [[FSCalendar alloc] initWithFrame:CGRectMake(0, 0, view.frame.size.width, height)];
calendar.dataSource = self;
calendar.delegate = self;

calendar.scopeGesture.enabled = YES;

[view addSubview:calendar];

// View 2 - TableView

_myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 200, SCREEN_WIDTH, SCREEN_HEIGHT) style:UITableViewStylePlain];
    self.myTableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight| UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
    self.myTableView.tableFooterView = [UIView new];
    self.myTableView.backgroundColor = self.view.backgroundColor;
    [self.myTableView  setShowsHorizontalScrollIndicator:NO];
    [self.myTableView setShowsVerticalScrollIndicator:NO];
  //  self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.myTableView.estimatedRowHeight = 85.0;
    self.myTableView.rowHeight = UITableViewAutomaticDimension;
    _myTableView.bounces = NO;
    self.myTableView.dataSource = self;
    self.myTableView.delegate = self;
    self.myTableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
    if (SYSTEM_VERSION_GREATER_THAN(@"8.4") && (IS_IPAD)){
        self.myTableView.cellLayoutMarginsFollowReadableWidth = NO;
    }

    [self.view addSubview:_myTableView];

我想问题可能就在这里:

_myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 200, SCREEN_WIDTH, SCREEN_HEIGHT) style:UITableViewStylePlain];

因为,我错过了大约200个空间点(我希望以编程方式向下移动表格视图的位置)。

有没有办法让屏幕高度符合我的观点?

1 个答案:

答案 0 :(得分:1)

如果此视图位于另一个视图中,则应在layoutSubviews

中调整其大小
- (void)layoutSubviews
{
    [super layoutSubviews];

    // your code here...
}

如果它在viewController的视图中,请在viewDidLayoutSubviews中调整大小。

- (void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];

    // your code here...
}