我需要创建一个“旧”风格的 UIView,没有 AutoLayout 和约束。在我看来,有一个 TableView 正在使用自动布局和另一个 View 计算它的大小。不幸的是, View 本身并没有提供我需要的高度。这就是我创建 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 点的空间(我想以编程方式向下移动表格 View 的 y 位置)。
有什么方法可以使屏幕高度适合我的 View 吗?
最佳答案
如果此 View 位于另一个 View 内,则应在 layoutSubviews
中调整其大小。
- (void)layoutSubviews
{
[super layoutSubviews];
// your code here...
}
如果它在 viewController 的 View 内,请在 viewDidLayoutSubviews
中调整大小。
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
// your code here...
}
关于ios - 在没有自动布局的情况下增加 UIView 的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38653206/