【发布时间】:2019-11-29 17:24:32
【问题描述】:
我有一个半透明且清晰的导航栏来显示表格视图标题的完整图像,同时仍然有导航按钮。但是,我想将 UITableView 标题中的一个项目限制在清晰导航栏的底部,并且它无法正常工作。
我目前使用导航栏高度的负填充值将表格视图限制在最顶部
我尝试获取导航栏高度并将其传递给 UITableView 单元类,但即使在 tableView.reload() 之后它也不起作用
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let cell = tableView.dequeueReusableCell(withIdentifier: "topCell") as! TopCell
let navHeight = CGFloat(UIApplication.shared.statusBarFrame.size.height +
(self.navigationController?.navigationBar.frame.height ?? 0.0))
cell.navBarHeight = navHeight
return cell
}
var navBarHeight: CGFloat = 0
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
addSubview(icon)
icon.anchor(top: topAnchor, left: leftAnchor, bottom: nil, right: nil, paddingTop: (CGFloat(navBarHeight + 10)), paddingLeft: 50, paddingBottom: 0, paddingRight: 0, width: 100, height: 100)
}
当前结果将图标限制在最顶部。
【问题讨论】:
标签: swift xcode uitableview uinavigationcontroller uikit