【发布时间】:2017-07-26 10:03:42
【问题描述】:
是否可以给 ui tableview 中的节标题一个偏移量以编程方式停止?
那么,节标题从顶部停止 100 像素?
【问题讨论】:
是否可以给 ui tableview 中的节标题一个偏移量以编程方式停止?
那么,节标题从顶部停止 100 像素?
【问题讨论】:
我认为这应该可行:
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)
}
}
}
【讨论】:
你可以试试这个
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);
部分标题现在将像任何常规单元格一样滚动。
【讨论】:
您可以使用 UIScrollView 的属性:contentInset。以及表格视图的样式UITableViewStyleGrouped (.group in Swift)。 这是我的此类 UI 示例:
如果您想避免标题移动,请将Bounce Vertical 属性设置为 NO。
【讨论】: