当为tableview插入头视图后,为了让tableview的起始位置显示正常,需要通过setContentOffset设置tableview的偏移位置: 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor(rgb: 0xeeeeee)
self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "back_bt_7"), style: .Plain,
target: self, action: #selector(AppSettingViewController.popPrevious))
tableview.delegate = self
tableview.dataSource = self
self.view.addSubview(tableview)
tableview.snp_makeConstraints { (make) -> Void in
make.edges.equalTo(self.view)
}
self.automaticallyAdjustsScrollViewInsets = false
let headImage = UIImage(named: "user_background")
headHeight = headImage!.size.height
tableview.contentInset = UIEdgeInsetsMake(headHeight, 0, 0, 0)
tableview.registerClass(YSettingCell.self, forCellReuseIdentifier: YSettingCell.CellIdentifier)
tableview.registerClass(UITableViewCell.self, forCellReuseIdentifier: "logoutIdentifier")
tableview.setContentOffset(CGPoint(x: 0, y: -headHeight), animated: true)
self.setupHeadView()
self.setupData()
}
设置setcontentoffset前:
设置setcontentoffset后: