使用动画调整UITableView标题的大小问题
问题描述:
我正在将我的表视图的标题高度设置为0以将其动画化。我现在用的是当前的代码:使用动画调整UITableView标题的大小问题
var newRect = headerView.frame
newRect.size.height = 0
UIView.animateWithDuration(0.6) {
self.headerView.frame = newRect
}
headerView
是一个自定义的UIView和像这样使用:
func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
return headerView
}
当我运行的代码,它似乎动画headerView
的高度正好一半大小而不是0.任何想法,我可能在这里做错了吗?任何指针都会很棒。
答
您只需使用heightForHeaderInSection
和UITableView
重新加载系统。贝娄,有一个如何去做的例子。这是一个虚拟的例子(当使用按下单元格时,它会使节标题(dis)出现。
var displayExpandedHeader = true
let expandedHeight = CGFloat(50)
let colapsedHeight = CGFloat(0)
func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
return headerView
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
tableView.beginUpdates()
displayExpandedHeader = !displayExpandedHeader
tableView.reloadSections(NSIndexSet(index: indexPath.section), withRowAnimation: (!displayExpandedHeader) ? .Top : .Bottom)
tableView.endUpdates()
}
func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return (displayExpandedHeader) ? expandedHeight : colapsedHeight
}
这帮了我,谢谢你的回答。 – Kex