我需要创建一个没有AutoLayout和约束的“旧”样式的UIView。在我看来,有一个表格视图正在使用自动布局和另一个视图来计算其大小。不幸的是,视图本身并没有提供我所需的高度。这就是我创建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个点的空间(我想以编程方式将表格视图向下移动的位置)。

有什么方法可以使屏幕高度适合我的视图?

最佳答案

如果此视图在另一个视图中,则应在layoutSubviews中调整其大小。

- (void)layoutSubviews
{
    [super layoutSubviews];

    // your code here...
}


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

- (void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];

    // your code here...
}

09-10 10:06
查看更多