我已将带有自定义 View 的标题添加到我的 TableView。它用作搜索栏,我设置了 contentOffset 所以它隐藏在开头。
一切都按预期工作,但我想知道是否有任何方法可以让它更难下拉? (应该更粘)现在只需常规滚动即可打开,这太容易了。
编辑:ScrollViewDidScroll 代码
if tableView.contentOffset.y < 80 && tableView.contentOffset.y > 40 {
subscriptionsTableView.contentOffset.y += 0.23
print("Content offset")
print(tableView.contentOffset.y)
}
最佳答案
我有一个类似的问题,最后很容易解决。我将表格 View 顶部插入设置为标题的高度
tableView.contentInset.top = -1 * headerView.frame.size.height
这使得标题显示在“屏幕外”,用户现在无法滚动到它。我添加了一个代码来将顶部插图更改为 0,当用户滚动到标题上方时显示标题
func scrollViewWillBeginDecelerating(_ scrollView: UIScrollView) {
if scrollView.contentOffset.y < 0 {
UIView.animate(withDuration: 0.25, animations: {
self.tableView.contentInset.top = 0
})
} else if scrollView.contentOffset.y > headerView.frame.size.height {
UIView.animate(withDuration: 0.25, animations: {
self.searchBar.resignFirstResponder()
self.tableView.contentInset.top = -1 * self.headerView.frame.size.height
})
}
}
当用户滚动表格 View 时,我还设置了顶部插图。
关于ios - 使 UITableView Header "stickier"更难下拉,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38498915/