1. tableview 的头部 有44的偏移量

1>.设置 tableview的 属性

        tableView.scrollIndicatorInsets = UIEdgeInsets.zero
self.translatesAutoresizingMaskIntoConstraints = false
if #available(iOS 11.0, *) {
tableView.contentInsetAdjustmentBehavior = .never
} else {
// Fallback on earlier versions
} 2>.在控制器设置属性
self.edgesForExtendedLayout = UIRectEdge(rawValue: 0)
if #available(iOS 11.0, *) {
extendedLayoutIncludesOpaqueBars = true
}else{
automaticallyAdjustsScrollViewInsets = false
}

  

2.获取VFL自定义view的宽和高

    func sizeToFitForView(temView:UIView) -> (height:CGFloat, width:CGFloat){
temView.setNeedsLayout()
temView.layoutIfNeeded()
let height = temView.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize).height
let width = temView.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize).width
return (height, width)
}

  

3.VFL自定义tableview的headerView 获取宽和高

    override func layoutSubviews() {
super.layoutSubviews()
sizeHeaderToFit()
}

  

    /// 重置 tableview的header的frame
private func sizeHeaderToFit() {
//FIXME: 这里一定要用过滤,不然会得到默认自带的headerView,高度还不可控
guard let headerView = tableView.tableHeaderView else { return }
headerView.setNeedsLayout()
headerView.layoutIfNeeded()
let height = headerView.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize).height
var frame = headerView.frame
frame.size.height = height
headerView.frame = frame
tableView.tableHeaderView = headerView
}

  

4.如果用VFL 设置 ScrollView约束子视图 宽度 给一个固定值 子视图高度 加上底部约束 就不用设置 contentsize

/// 添加ScrollView的子控件

    func setScrollVSubviews(){

        let vd : [String : UIView] = ["discountView":discountView,

                                      "shopInfoView": shopInfoView,

                                      "itemsView":itemsView,

                                      "employeesInfoView":employeesInfoView]

        vd.fastAddToView(scrollV)

        scrollV.fastAddConstraints("|[discountView(\(JY_DEVICE_WIDTH))]", vd)

        scrollV.fastAddConstraints("|[shopInfoView(\(JY_DEVICE_WIDTH))]", vd)

        scrollV.fastAddConstraints("|[itemsView(\(JY_DEVICE_WIDTH))]", vd)

        scrollV.fastAddConstraints("|[employeesInfoView(\(JY_DEVICE_WIDTH))]", vd)

        scrollV.fastAddConstraints("V:|[discountView][shopInfoView][itemsView][employeesInfoView]|", vd)

    }

  

05-02 13:30