[英]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.