Commit 17e64a7a authored by David黄金龙's avatar David黄金龙

Merge branch 'youhua-dev' of http://gitlab.galaxy-immi.com/mobile-group/galaxy-iOS into youhua-dev

* 'youhua-dev' of http://gitlab.galaxy-immi.com/mobile-group/galaxy-iOS:
  // 生活详情
  //  生活详情
parents af64ad61 72c04dde
......@@ -129,7 +129,7 @@ class YHLifeDetailViewController: YHBaseViewController {
imgView.image = UIImage(named: "global_default_image")
return imgView
}()
lazy var segmentedView : JXSegmentedView = {
let segmentedView = JXSegmentedView(frame: CGRect(x: 0, y: 0, width: KScreenWidth, height: 44))
segmentedView.delegate = self
......@@ -240,6 +240,7 @@ extension YHLifeDetailViewController: JXSegmentedViewDelegate {
if segmentedView == self.topSegmentedView {
self.segmentedView.defaultSelectedIndex = index
self.segmentedView.reloadDataWithoutListContainer()
} else {
self.topSegmentedView.defaultSelectedIndex = index
self.topSegmentedView.reloadDataWithoutListContainer()
......@@ -247,9 +248,9 @@ extension YHLifeDetailViewController: JXSegmentedViewDelegate {
if 0 <= index, index < self.imgItems.count {
self.fakeTableView.scrollToRow(at: IndexPath(row: index, section: 0), at: .top, animated: true)
let rect = self.fakeTableView.rectForRow(at: IndexPath(row: index, section: 0))
DispatchQueue.main.asyncAfter(deadline: .now()+0.2, execute: {
var y = rect.origin.y - k_Height_NavigationtBarAndStatuBar-45.0
DispatchQueue.main.asyncAfter(deadline: .now()+0.3, execute: {
let rect = self.fakeTableView.rectForRow(at: IndexPath(row: index, section: 0))
var y = rect.origin.y - k_Height_NavigationtBarAndStatuBar-45.0+2.0
if y > self.fakeTableView.contentSize.height-self.fakeTableView.height {
y = self.fakeTableView.contentSize.height-self.fakeTableView.height
}
......@@ -273,31 +274,57 @@ extension YHLifeDetailViewController: UIScrollViewDelegate {
topSegmentedView.isHidden = true
topLine.isHidden = true
}
var find = false
}
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
if scrollView == self.fakeTableView {
return
}
self.updateSelectIndex(scrollView)
}
func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
if scrollView == self.fakeTableView {
return
}
self.updateSelectIndex(scrollView)
}
func updateSelectIndex(_ scrollView: UIScrollView) {
var selectIndex = -1
if self.imgItems.count > 0 {
for index in 0..<self.imgItems.count {
let rect = self.tableView.rectForRow(at: IndexPath(row: index, section: 0))
// section 到顶部选择tab的距离
// row 到顶部选择tab的距离 row 在tab下方 距离为证, row 在tab上方 距离为负
let y = rect.origin.y-k_Height_NavigationtBarAndStatuBar-45.0-self.tableView.contentOffset.y
if 0.0 <= y, y < self.tableView.height-k_Height_NavigationtBarAndStatuBar-45.0 {
find = true
self.topSegmentedView.defaultSelectedIndex = index
self.topSegmentedView.reloadDataWithoutListContainer()
self.segmentedView.defaultSelectedIndex = index
self.segmentedView.reloadDataWithoutListContainer()
if y > -rect.size.height {
selectIndex = index
break
}
}
}
// section 没有在可见区域出现
if !find {
if selectIndex < 0 {
if let arr = self.tableView.indexPathsForVisibleRows, let lastIndexPath = arr.last {
self.topSegmentedView.defaultSelectedIndex = lastIndexPath.row
self.topSegmentedView.reloadDataWithoutListContainer()
self.segmentedView.defaultSelectedIndex = lastIndexPath.row
self.segmentedView.reloadDataWithoutListContainer()
selectIndex = lastIndexPath.row
}
} else {
if self.imgItems.count >= 2 {
let gap = self.tableView.contentSize.height-self.tableView.contentOffset.y
if selectIndex == self.imgItems.count-2, self.tableView.height-1.0 <= gap, gap <= self.tableView.height+1.0 {
// 滑动到底部需要定位到最后一个index
selectIndex = self.imgItems.count-1
}
}
}
self.topSegmentedView.defaultSelectedIndex = selectIndex
self.topSegmentedView.reloadDataWithoutListContainer()
self.segmentedView.defaultSelectedIndex = selectIndex
self.segmentedView.reloadDataWithoutListContainer()
}
}
......@@ -329,7 +356,7 @@ extension YHLifeDetailViewController: UITableViewDataSource, UITableViewDelegate
}
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return KScreenHeight/3.0
return 0.01
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
......@@ -339,30 +366,6 @@ extension YHLifeDetailViewController: UITableViewDataSource, UITableViewDelegate
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
return UIView()
}
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
if tableView == self.fakeTableView {
return
}
if 0 <= indexPath.row, indexPath.row < self.imgItems.count {
self.segmentedView.defaultSelectedIndex = indexPath.row
self.segmentedView.reloadDataWithoutListContainer()
self.topSegmentedView.defaultSelectedIndex = indexPath.row
self.topSegmentedView.reloadDataWithoutListContainer()
}
}
func tableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath) {
if tableView == self.fakeTableView {
return
}
if 0 <= indexPath.row-1, indexPath.row-1 < self.imgItems.count {
self.segmentedView.defaultSelectedIndex = indexPath.row-1
self.segmentedView.reloadDataWithoutListContainer()
self.topSegmentedView.defaultSelectedIndex = indexPath.row-1
self.topSegmentedView.reloadDataWithoutListContainer()
}
}
}
extension YHLifeDetailViewController {
......@@ -404,10 +407,10 @@ extension YHLifeDetailViewController {
self.headImgView.snp.updateConstraints { make in
make.height.equalTo(imgHeight)
}
self.headerView.setNeedsLayout()
self.headerView.layoutIfNeeded()
self.tableView.tableHeaderView = self.headerView
self.fakeTableView.tableHeaderView?.height = self.headerHeight
self.fakeTableView.tableHeaderView = UIView(frame: CGRect(x: 0, y: 0, width: KScreenWidth, height: self.headerHeight))
self.view.setNeedsLayout()
self.view.layoutIfNeeded()
case .failure(let error):
print("image download failed: \(error.localizedDescription)")
......@@ -435,7 +438,16 @@ extension YHLifeDetailViewController {
ossGroup.notify(queue: .main) {
self.tableView.reloadData()
self.fakeTableView.reloadData()
self.fakeTableView.reloadData {
DispatchQueue.main.asyncAfter(deadline: .now()+0.3, execute: {
self.fakeTableView.setContentOffset(.zero, animated: false)
if self.imgItems.count > 0 {
self.fakeTableView.scrollToRow(at: IndexPath(row: self.imgItems.count-1, section: 0), at: .top, animated: true)
}
self.fakeTableView.setNeedsLayout()
self.fakeTableView.layoutIfNeeded()
})
}
}
}
}
......
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