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

标签 ios objective-c uiview

我需要创建一个“旧”风格的 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/

相关文章:

ios - 如何长时间显示iPhone App中的默认图片?

ios - tvOS 聚焦 SegmentedControl

ios - 谷歌地图 iOS MapView

ios - 如何在 iOS 中从 ms-word 或 ms-excel 打开 excel、doc

ios - 从程序执行 .addSubview 到 View 实际出现的意外延迟 - Swift

ios - 在 for 循环中处理 UI 更新 - iOS

iphone - 将 NSDate 转换为 NSString

iphone - iOS数组没有被完全填满

uiview - 在哪里放置父 View 使用自动布局的 UIView 的手动布局代码?

ios - 在 View 中提高过渡平滑度