禁用 tableHeaderView(不要与节标题混淆)滚动 [英] disable tableHeaderView (Not to be confused with section header) scrolling

查看:29
本文介绍了禁用 tableHeaderView(不要与节标题混淆)滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以禁用 tableHeaderView 的滚动(不要与节标题混淆).现在每当我滚动表格时,tableHeaderView 中的视图也会滚动.

Is it possible to disable the scrolling of tableHeaderView (Not to be confused with section header).Right now whenever I scroll the table, view in the tableHeaderView also gets scrolled.

我在做什么:

  1. 我有一个从 UITableViewController 继承的类.
  2. 在故事板中,我使用的是静态表格视图.
  3. 表格样式已分组,我添加了 8 个部分,每个部分各有一行.
  4. 在第一部分的顶部,添加了一个视图,即 tableHeaderView.

我想在滚动表格时禁用标题为个人资料"的视图滚动.

I want to disable the scrolling of view with title "Profile" when I scroll the table.

附注:我知道如果我从 UIViewController 而不是 UITableViewController 继承我的类,这是可以实现的.但我不想 UIViewController 因为我使用故事板来设计静态单元格 如果我使用 UIViewController 而不是 UITableViewController 那么编译器会抛出警告静态表视图仅在嵌入 UITableViewController 实例时才有效"

PS: I know this is achievable if I subclassed my class from UIViewController instead of UITableViewController. But I don't want to UIViewController because I am using storyboard for designing static cell and If I use UIViewController instead of UITableViewController then compiler throws a warning "Static table views are only valid when embedded in UITableViewController instances"

请告诉我哪种方法是实现此目的的最佳方法.是否可以使用我当前的方法禁用 tableHeader 的滚动,或者我是否需要使用 UIViewController.

Please let me know which is the best approach to achieve this.Is it possible to disable the scrolling of tableHeader using my current approach or do I need to use UIViewController instead.

推荐答案

只需使用带有父 UIViewController 的 embed segue,该父UIViewController 由标题视图和容器视图组成.将您的 UITableViewController 嵌入到容器视图中.这个答案中的更具体步骤.

Just use an embed segue with a parent UIViewController consisting of a header view and a container view. Embed your UITableViewController in the container view. More specific steps in this answer.

如果你想要 UITableViewController 中的所有东西,你可以插入你自己的子视图,这样做:

If you want everything in UITableViewController, you can insert your own subview doing something like this:

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.header = [[UIView alloc] init];
    self.header.frame = CGRectMake(0, 0, self.tableView.bounds.size.width, 44);
    self.header.backgroundColor = [UIColor greenColor];
    [self.tableView addSubview:self.header];
    self.tableView.contentInset = UIEdgeInsetsMake(44, 0, 0, 0);
}

然后在scrollViewDidScroll和朋友中操作视图的位置:

and then manipulate the position of the view in scrollViewDidScroll and friends:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    self.header.transform = CGAffineTransformMakeTranslation(0, self.tableView.contentOffset.y);
}

我说和朋友"是因为你需要处理像 scrollViewDidScrollToTop: 这样的极端情况.scrollViewDidScroll 在滚动期间的每个显示周期中都会被调用,因此这样做看起来完美无缺.

I say "and friends" because you'd need to take care of the corner cases like scrollViewDidScrollToTop:. scrollViewDidScroll gets called in every display cycle during scrolling, so doing it this way looks flawless.

这篇关于禁用 tableHeaderView(不要与节标题混淆)滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆