【问题标题】:How can I finished one view's constrains before other view generate如何在另一个视图生成之前完成一个视图的约束
【发布时间】:2016-06-17 03:27:49
【问题描述】:

现在,我要生成一个titleview,它的高度对于tableHeaderView是可变的。所以我需要在tableview生成之前确认titleview的hegiht

//titleView
JMProductTitleView *titleView = [[JMProductTitleView alloc]initWithFrame:CGRectMake(0, 0, JMDeviceWidth, 300)];
titleView.delegate = self;
JMProductDetailModel *model = [JMPorductDetailTool createProductDetailModel];
titleView.model = model;
_titleView = titleView;

//
UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, JMDeviceWidth, JMDeviceHeight) style:UITableViewStylePlain];
tableView.delegate = self;
tableView.dataSource = self;
tableView.tableHeaderView = titleView;
[self.view addSubview:tableView];
_tableView = tableView;

【问题讨论】:

  • 您可以尝试使用 [self.view layoutIfNeeded]。它将强制视图布局所有约束。
  • 太棒了!它对我有用。非常感谢。我使用过 [self.view setNeedsLayout],但没有用。我不知道为什么。你能告诉我它们之间的区别吗?
  • 嗯,我不确定自己,除了我所知道的是,layoutIfNeeded 在内部调用所有强制 UI 进行设置的函数。转到此页面,它可能会清除一些东西stackoverflow.com/questions/2807137/… 另外我会将其添加为答案,因为它可以解决您的问题。

标签: ios objective-c constraints


【解决方案1】:

您可以尝试使用 [self.view layoutIfNeeded]。它将强制视图布局所有约束。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-24
    • 2018-05-02
    • 1970-01-01
    • 1970-01-01
    • 2021-06-28
    • 2021-09-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多