UITableView可以在UIVIewController中滚动。

3

我有一个简单的UIViewController,其中包含两个子视图,如下图所示:

enter image description here

我的目标是当向下滚动UITableView内容时,也将顶部的UIView推出。

比如说,我想要复制UITableView的Header行为。

是否可以在不使用表头的情况下实现?

非常感谢您的帮助。


重写 scrollView 委托方法并检测用户是否朝特定方向滚动。根据滚动距离手动隐藏 view - Blind Ninja
1个回答

1
从我的记忆中,这大概是它应该如何工作的。
override func scrollViewDidScroll(scrollView: UIScrollView) {
    let yPosition = scrollView.contentOffset.y
    if (yPosition > yourView.frame.size.height) {
        return;
    }
    yourView.frame = CGRectMake(0, -yPosition, yourView.frame.size.width, yourView.frame.size.height)
    tableView.frame = GRectMake(0, yourView.frame.origin.y + self.yourView.frame.size.height,  tableView.frame.size.width, tableView.frame.size.height)
}

您可能需要调整框架定位逻辑,这是我脑海中想到的。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接