gpt4 book ai didi

ios - 如何阻止 UIView 与 tableview 一起滚动?

转载 作者:搜寻专家 更新时间:2023-11-01 06:21:08 25 4
gpt4 key购买 nike

我有一个 UITableViewController,我将 UIView 放在导航项的正下方和实际表格的上方。我遇到的问题是 View 与 tableview 一起滚动。

我如何让它的行为与导航栏完全一样,并让 tableview 中的项目在它后面滚动。

与其让 View 滚动,不如让它保持在原位,让一切都在它后面。抱歉再次重申,但我发现有时这是必要的。

enter image description here

最佳答案

您放置在 Storyboard 中单元格上方的 View 成为 TableView 的 tableHeaderView

每次 TableView 布局其 subview 时,您可以通过将其 frame.origin 重置为 TableView 的 bounds.origin 来使标题 View 看起来固定:

- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];

UIView *header = self.tableView.tableHeaderView;
CGRect frame = header.frame;
frame.origin = self.tableView.bounds.origin;
header.frame = frame;
}

结果:

demo of stationary table view header

关于ios - 如何阻止 UIView 与 tableview 一起滚动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33908252/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com