【问题标题】:UITableView section's header hight: how to smoothly change it in swift?UITableView 部分标题高度:如何快速平滑地更改它?
【发布时间】:2017-04-26 19:14:58
【问题描述】:

我正在尝试通过这种方法将高度乘数从 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

【问题讨论】:

    标签: ios swift uitableview


    【解决方案1】:

    要更改标题部分的高度,请覆盖方法heightForHeaderInSection

    public override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 20
    }
    

    这可能会解决您的问题。

    【讨论】:

    • 感谢您的帮助!
    【解决方案2】:

    我建议在设置标题视图本身时添加一个过渡,而不是尝试在显示时设置动画。 请添加您选择的动画

    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
    }
    

    【讨论】:

    • 有效!谢谢!但是它是空的,因为干净的 UIView 没有文本标签。我这样修复它: let aHeader = UITableViewHeaderFooterView() let header = aHeader as UIView
    猜你喜欢
    • 2013-07-16
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    • 2016-07-05
    • 2019-04-20
    • 2019-08-14
    • 2010-11-17
    • 1970-01-01
    相关资源
    最近更新 更多