ios - 快速滚动时更改UITableView标题高度
<p><p>当我以特定偏移量滚动时如何更改我的 tableview 标题高度?
这是我的标题实现,我使用自定义单元格作为标题。
但基本上我要做的是在滚动到某个偏移量时显示和隐藏标题。</p>
<pre><code>func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
letcell = tableView.dequeueReusableHeaderFooterViewWithIdentifier("tableViewHeader") as! MyTableViewHeaderCell
return cell
}
func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 70
}
func scrollViewWillBeginDragging(scrollView: UIScrollView) {
if (scrollView.contentOffset.y>400){
// i want to try to change the height of header to be 0/hidden
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我希望这样做来处理标题高度</p>
<pre><code>func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
if (myScrollView.contentOffset.y>400){
return 70
} else {
return 0
}
}
</code></pre>
<p>这是管理表格 View 的标题更新</p>
<pre><code>func scrollViewWillBeginDragging(scrollView: UIScrollView) {
if (scrollView.contentOffset.y>400 && itWasLessThan400 == true) {
itWasLessThan400 = false
myTableView.reloadData() //or reload only the needed section if you have more than one sections
} else if (scrollView.contentOffset.y<400 && itWasLessThan400 == false) {
itWasLessThan400 = true
myTableView.reloadData() //or reload only the needed section if you have more than one sections
} else
}
</code></pre>
<p>并确保在 viewController 中的 <code>viewDidLoad</code> 处设置 <code>itWasLessThan400 = true</code></p>
<p>我希望这会有所帮助:)</p></p>
<p style="font-size: 20px;">关于ios - 快速滚动时更改UITableView标题高度,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/39243304/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/39243304/
</a>
</p>
页:
[1]