如何检测何时将UITableView标头滚动到可见区域之外? [英] How to detect when a UITableView header is scrolled off visible area?

查看:78
本文介绍了如何检测何时将UITableView标头滚动到可见区域之外?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检测何时将UITableView标头(表标头,而不是节标头)滚动到可见区域之外?

How to detect when a UITableView header (table header, not section header) is scrolled off visible area?

提前谢谢!

推荐答案

我可以想到几种可能的解决方案:

There are couple of possible solutions I can think of:

1) 您可以使用此委托的方法:

1) You can use this delegate's method:

tableView:didEndDisplayingHeaderView:forSection:

tableView:didEndDisplayingHeaderView:forSection:

但是,仅当您在方法中提供标头时,才会调用此方法

However, this method is called only if you provide header in the method

tableView:viewForHeaderInSection:

tableView:viewForHeaderInSection:

您说的是不是节标题",但是您可以将分组的tableView中的第一个节标题用作表headerView. (分组的标题将与表格视图一起滚动)

You said 'not section header', but you can use the first section header in a grouped tableView as the table headerView. (The grouped is for the header will scroll together with the table view)

2) 如果您不想使用分组的tableView和section标头,则可以使用scrollView的委托(UITableViewDelegate符合UIScrollViewDelegate).只需检查tableView何时滚动足以使tableHeaderView消失即可.请参见以下代码:

2) If you don't want to use grouped tableView and the section header, you can use the scrollView's delegate (UITableViewDelegate conforms to UIScrollViewDelegate). Just check when the tableView is scrolled enough for disappearing the tableHeaderView. See the following code:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {

    static CGFloat lastY = 0;

    CGFloat currentY = scrollView.contentOffset.y;
    CGFloat headerHeight = self.headerView.frame.size.height;

    if ((lastY <= headerHeight) && (currentY > headerHeight)) {
        NSLog(@" ******* Header view just disappeared");
    }

    if ((lastY > headerHeight) && (currentY <= headerHeight)) {
        NSLog(@" ******* Header view just appeared");
    }

    lastY = currentY;
}

希望它会有所帮助.

这篇关于如何检测何时将UITableView标头滚动到可见区域之外?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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