Commit 62b6b104 authored by pete谢兆麟's avatar pete谢兆麟

定位相关问题

parent 729fbeb0
......@@ -15,8 +15,11 @@ class YHMakePlanViewController: YHBaseViewController {
lazy var headView: YHMakePlanHeadView = {
let view = YHMakePlanHeadView(frame: CGRect(x: 0, y: 0, width: KScreenWidth, height: 333.fix + 44))
view.block = { tag in
self.tableView.scrollToRow(at: IndexPath(row: tag, section: 0), at: .top, animated: true)
self.topView.custtomView.updataData(tag)
let indexPath = IndexPath(row: tag, section: 0)
let cellRect: CGRect = self.tableView.rectForRow(at: indexPath)
let targetY = cellRect.origin.y - 104 - k_Height_NavigationtBarAndStatuBar
self.tableView.setContentOffset(CGPoint(x: 0, y: targetY), animated: true)
}
return view
}()
......@@ -46,8 +49,11 @@ class YHMakePlanViewController: YHBaseViewController {
let view = YHMakePlanTopView()
view.isHidden = true
view.block = { tag in
self.tableView.scrollToRow(at: IndexPath(row: tag, section: 0), at: .top, animated: true)
self.headView.custtomView.updataData(tag)
let indexPath = IndexPath(row: tag, section: 0)
let cellRect: CGRect = self.tableView.rectForRow(at: indexPath)
let targetY = cellRect.origin.y - 104 - k_Height_NavigationtBarAndStatuBar
self.tableView.setContentOffset(CGPoint(x: 0, y: targetY), animated: true)
}
return view
}()
......@@ -279,12 +285,19 @@ extension UITableView {
/// 获取当前显示在最顶部的行索引
func topVisibleRowIndex() -> Int? {
// 获取所有可见行的indexPath(按从上到下的顺序排列)
guard let visibleIndexPaths = self.indexPathsForVisibleRows?.sorted() else {
return nil
let visibleRect = CGRect(
x: self.contentOffset.x,
y: self.contentOffset.y + 104 + k_Height_NavigationtBarAndStatuBar, // 向下偏移 187px
width: self.bounds.width,
height: self.bounds.height
)
// 获取该区域内的所有行
guard let indexPaths = self.indexPathsForRows(in: visibleRect) else {
return 0
}
// 第一个就是最顶部的行
return visibleIndexPaths.first?.row
return indexPaths.first?.row
}
/// 获取当前显示在最顶部的单元格
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment