Ios UITableView节收割台停止位置
是否可以为ui tableview中的节标题提供一个偏移量以编程方式停止Ios UITableView节收割台停止位置,ios,swift,Ios,Swift,是否可以为ui tableview中的节标题提供一个偏移量以编程方式停止 因此,节头从顶部停止100 px?您可以使用UIScrollView的属性:。和表格视图的样式。 这是我的UI示例: 如果要避免标题移动,请将属性设置为“否”。您可以尝试此选项 CGFloat newViewHeight = 40; UIView *newView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.bounds.size.wi
因此,节头从顶部停止100 px?您可以使用UIScrollView的属性:。和表格视图的样式。 这是我的UI示例: 如果要避免标题移动,请将属性设置为“否”。您可以尝试此选项
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);
节标题现在将像任何常规单元格一样滚动。我认为这应该可以:
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)
}
}
}
覆盖函数scrollViewDidScroll(scrollView:UIScrollView)
{
super.scrollViewDidScroll(scrollView)
让我们插入:CGFloat=73
如果scrollView.contentOffset.y0{
scrollView.contentInset=UIEdgeInSet(顶部:scrollView.contentOffset.y,左侧:0,底部:0,右侧:0)
}否则{
如果scrollView.contentOffset.y<0{
scrollView.contentInset=UIEdgeInSet(顶部:0,左侧:0,底部:0,右侧:0)
}否则{
scrollView.contentInset=UIEdgeInSet(顶部:插入,左侧:0,底部:0,右侧:0)
}
}
}
检查此项谢谢您的评论,uiedgeinset使用标题是正确的,但是内容也会获得偏移量,但我只想更早地停止标题,因为tableview位于透明视图后面