【问题标题】:UITableView Section Header Stop PositionUITableView 节标题停止位置
【发布时间】:2017-07-26 10:03:42
【问题描述】:

是否可以给 ui tableview 中的节标题一个偏移量以编程方式停止?

那么,节标题从顶部停止 100 像素?

【问题讨论】:

标签: ios swift


【解决方案1】:

我认为这应该可行:

override func scrollViewDidScroll(_ scrollView: UIScrollView)
{
    super.scrollViewDidScroll(scrollView)
    let inset: CGFloat = 73
    if scrollView.contentOffset.y < inset && scrollView.contentOffset.y > 0 {
        scrollView.contentInset = UIEdgeInsets(top: scrollView.contentOffset.y, left: 0, bottom: 0, right: 0)
    } else {
        if scrollView.contentOffset.y < 0 {
            scrollView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
        } else {
            scrollView.contentInset = UIEdgeInsets(top: inset, left: 0, bottom: 0, right: 0)
        }
    }
}

【讨论】:

    【解决方案2】:

    你可以试试这个

    CGFloat newViewHeight = 40;
    
    UIView *newView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.bounds.size.width, newViewHeight)];
    
    self.tableView.tableHeaderView = newView;
    self.tableView.contentInset = UIEdgeInsetsMake(-newViewHeight, 0, 0, 0);
    

    部分标题现在将像任何常规单元格一样滚动。

    【讨论】:

      【解决方案3】:

      您可以使用 UIScrollView 的属性:contentInset。以及表格视图的样式UITableViewStyleGrouped (.group in Swift)。 这是我的此类 UI 示例:

      如果您想避免标题移动,请将Bounce Vertical 属性设置为 NO。

      【讨论】:

      • 感谢您的评论,UIEdgeInsets 用标题做了正确的事情,但内容也得到了偏移量,但我只想早点停止标题,因为 tableview 在透明视图后面跨度>
      猜你喜欢
      • 1970-01-01
      • 2012-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多