pravir
pravir

Reputation: 392

Detect direction of drag when trying to scroll beyond the limits of scrollView

In my vertical scrollView (having 2 containerViews of the size of device screen) I want to hide a View (added to my window) when user scrolls down, but don't want to hide it when the user scrolls up, i.e., when scrollView's contentOffset.y is currently 0 and on again trying to scroll it remains to be 0 only.

if self.scrollView.contentOffset.y == 0
{
    myView.isHidden = true
} 
else if self.scrollView.contentOffset.y > 0 {
    myView.isHidden = true
}

Upvotes: 2

Views: 819

Answers (1)

Kevinosaurio
Kevinosaurio

Reputation: 2010

set scrollViewDelegate to VC, then:

func scrollViewDidScroll(scrollView: UIScrollView) {
    myView.isHidden = scrollView.panGestureRecognizer.translationInView(scrollView.superview).y < 0
}

Upvotes: 2

Related Questions