在我的应用程序中,我有顶部导航栏和导航栏下方的表格视图。我有两行的 CollectionViewCell,它们以编程方式添加到 UITableViewHeader 中。当我将 TableView 滚动到顶部时,我希望标题在导航栏下方停止,并更新 TableView 标题高度,以便我只能显示一行。当 TableViewHeader 粘在导航栏上时,我只想做一个动画(比如 Shrinked),两个 collectionview 行应该通过降低 Header Height 变成一行。我怎样才能以编程方式做到这一点
下面是我显示 CustomHeaderView 的代码
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let headerView = UIView.init(frame: CGRect(x: 0, y: 0, width: self.view.frame.width, height: 183))
let headerCell = tableView.dequeueReusableCell(withIdentifier: kLastPlayedidentifier) as! LastPlayedTVC
headerCell.frame = headerView.frame
headerCell.category = lastPlayedData
headerView.addSubview(headerCell)
return headerView
}
此外,我正在检查滚动位置以编程方式设置 tableview 标题高度,这对我来说并不成功。
func scrollViewDidScroll(_ scrollView: UIScrollView) {
print(scrollView.contentOffset)
if scrollView.contentOffset.y > 237 //This value is to check when the header reached the top position {
//Condition to check and animate the headerview height to make collectionview cell two rows into one rows.
}
当标题在滚动时粘在顶部时,如何实现 TableViewHeader 高度更新。
任何帮助表示赞赏。