Skip to content

Commit

Permalink
fix #2
Browse files Browse the repository at this point in the history
  • Loading branch information
bawn committed Sep 10, 2019
1 parent 5f603e0 commit 57dcb46
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions Aquaman/Aquaman/AquamanPageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,15 @@ open class AquamanPageViewController: UIViewController, AMPageControllerDataSour
currentChildScrollView = currentViewController?.aquamanChildScrollView()
currentIndex = index

childScrollViewObservation?.invalidate()
let keyValueObservation = currentChildScrollView?.observe(\.contentOffset, options: [.new, .old], changeHandler: { [weak self] (scrollView, change) in
guard let self = self, change.newValue != change.oldValue else {
return
}
self.childScrollViewDidScroll(scrollView)
})
childScrollViewObservation = keyValueObservation

if let viewController = containView.viewController {
pageController(self, didDisplay: viewController, forItemAt: index)
}
Expand Down Expand Up @@ -356,7 +365,7 @@ open class AquamanPageViewController: UIViewController, AMPageControllerDataSour
currentChildScrollView = nil

headerView?.removeFromSuperview()
contentScrollView.setContentOffset(.zero, animated: false)
contentScrollView.contentOffset = .zero

contentStackView.arrangedSubviews.forEach({$0.removeFromSuperview()})
memoryCache.removeAllObjects()
Expand Down Expand Up @@ -412,7 +421,6 @@ open class AquamanPageViewController: UIViewController, AMPageControllerDataSour
}

let containView = containViews[index]

guard containView.isEmpty else {
return
}
Expand All @@ -438,21 +446,13 @@ open class AquamanPageViewController: UIViewController, AMPageControllerDataSour
containView.viewController = targetViewController

let scrollView = targetViewController.aquamanChildScrollView()

scrollView.am_originOffset = scrollView.contentOffset
if mainScrollView.contentOffset.y < sillValue {
scrollView.contentOffset = scrollView.am_originOffset
scrollView.am_isCanScroll = false
mainScrollView.am_isCanScroll = true
}

childScrollViewObservation?.invalidate()
let keyValueObservation = scrollView.observe(\.contentOffset, options: [.new, .old], changeHandler: { [weak self] (scrollView, change) in
guard let self = self, change.newValue != change.oldValue else {
return
}
self.childScrollViewDidScroll(scrollView)
})
childScrollViewObservation = keyValueObservation
}


Expand Down Expand Up @@ -540,6 +540,7 @@ open class AquamanPageViewController: UIViewController, AMPageControllerDataSour
}

open func pageController(_ pageController: AquamanPageViewController, mainScrollViewDidScroll scrollView: UIScrollView) {

}


Expand Down Expand Up @@ -638,7 +639,6 @@ extension AquamanPageViewController: UIScrollViewDelegate {

extension AquamanPageViewController {
private func childScrollViewDidScroll(_ scrollView: UIScrollView) {

if scrollView.am_isCanScroll == false {
scrollView.contentOffset = scrollView.am_originOffset
}
Expand Down

0 comments on commit 57dcb46

Please sign in to comment.