[英]UITableView section's header hight: how to smoothly change it in swift?
我正在尝试通过以下方法通过将高度乘数从0更改为1来创建tableView节标题的平滑外观:
.sectionHeaderHeight.multiply(by:_)其中_应该是CGFloat。
编码:
override func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
tableView.sectionHeaderHeight.multiply(by: _)
}
不幸的是,标题似乎只能接受0(隐藏)或1。
1以上的所有内容都会破坏UI,0到1之间的所有内容都会产生error
:
***-[UISectionRowData refreshWithSection:tableView:tableViewRowData:],/ BuildRoot / Library / Caches / com.apple.xbs / Sources / UIKit_Sim / UIKit-3600.7.47 / UITableViewRowData.m:443中的断言失败
要更改页眉节的高度,请重写heightForHeaderInSection
方法。
public override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 20
}
这可能会解决您的问题。
建议您在设置标题视图本身时添加一个过渡,而不是尝试对其显示时进行动画处理。 请添加您选择的动画
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let aHeader = UITableViewHeaderFooterView()
let header = aHeader as UIView
var headerFrame = tableView.frame
headerFrame.size.height = 100
header.frame = headerFrame
let transition = CATransition()
transition.duration = 1.0;
transition.type = kCATransitionPush; //choose your animation
header.layer.add(transition, forKey: nil)
return header
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 100
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.