Skip to content

Commit

Permalink
Merge commit from 1.1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
bsv-hienpham1991 committed Jul 2, 2021
1 parent 18bb70b commit 8193743
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
32 changes: 28 additions & 4 deletions HPParallaxHeader/Classes/HPScrollView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ open class HPScrollView : UIScrollView {
private var observedViews: [UIScrollView] = []
private var isObserving: Bool = true
private var lock: Bool = false
private var isScrollingToTop: Bool = false

override init(frame: CGRect) {
super.init(frame: frame)
Expand Down Expand Up @@ -80,6 +81,7 @@ extension HPScrollView: UIGestureRecognizerDelegate {
public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer,
shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
if (otherGestureRecognizer.view == self) {
isScrollingToTop = false
return false
}

Expand Down Expand Up @@ -169,7 +171,7 @@ extension HPScrollView {
if scrollView == self {

//Adjust self scroll offset when scroll down
if (diff > 0 && lock) {
if (diff > 0 && lock && isScrollingToTop == false) {
self.scrollView(self, setContentOffset: old)
} else if contentOffset.y < -contentInset.top && !bounces {
self.scrollView(self, setContentOffset: CGPoint(x: contentOffset.x,
Expand All @@ -178,8 +180,12 @@ extension HPScrollView {
self.scrollView(self, setContentOffset: CGPoint(x: contentOffset.x,
y: -parallaxHeader.minimumHeight))
}

} else {

// Check and update isScrollingToTop
if contentOffset.y <= -parallaxHeader.height {
isScrollingToTop = false
}
} else {
//Adjust the observed scrollview's content offset
lock = (scrollView.contentOffset.y > -scrollView.contentInset.top)

Expand All @@ -195,7 +201,14 @@ extension HPScrollView {
}
}
}


/**
Scroll to top manually which show parallax header totally
*/
open func hpScrollsToTop(animated: Bool) {
isScrollingToTop = true
setContentOffset(CGPoint(x: 0, y: -parallaxHeader.height), animated: animated)
}
}

// MARK: - Scrolling views handlers
Expand All @@ -218,6 +231,17 @@ extension HPScrollView {
}
}


//@implementation MXScrollViewDelegateForwarder
//
//- (BOOL)respondsToSelector:(SEL)selector {
// return [self.delegate respondsToSelector:selector] || [super respondsToSelector:selector];
//}
//
//- (void)forwardInvocation:(NSInvocation *)invocation {
// [invocation invokeWithTarget:self.delegate];
//}

// MARK: - <UIScrollViewDelegate>
extension HPScrollView: UIScrollViewDelegate {
public func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
Expand Down
6 changes: 5 additions & 1 deletion HPParallaxHeader/Classes/HPScrollViewDelegateForwarder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ import UIKit
}

@objc func scrollViewShouldScrollToTop(_ scrollView: UIScrollView) -> Bool {
return delegate?.scrollViewShouldScrollToTop?(scrollView) ?? scrollView.scrollsToTop
let isScrollToTop = delegate?.scrollViewShouldScrollToTop?(scrollView) ?? scrollView.scrollsToTop
if isScrollToTop == true {
self.scrollView.hpScrollsToTop(animated: true)
}
return false
}

@objc func scrollViewDidScrollToTop(_ scrollView: UIScrollView) {
Expand Down

0 comments on commit 8193743

Please sign in to comment.