[英]iOS Change UITableView header height when scroll swift
当我以特定偏移量滚动时,如何更改tableview标头高度? 这是我的标头实现,我使用自定义单元格作为标头。 但是基本上我想做的是在滚动一定偏移量时显示和隐藏标题。
func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let cell = 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
}
我想这样处理标题高度
func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
if (myScrollView.contentOffset.y>400){
return 70
} else {
return 0
}
}
这用于管理表视图的标题更新
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
}
并确保在itWasLessThan400 = true
viewDidLoad
处将其设置为itWasLessThan400 = true
我希望这有帮助 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.