UIScrollView should only scroll down
I have a scrollview and I want this scroll to only show the scroll down , and it shouldn't scroll in any other direction. This is not about horizontal or vertical, but rather that I want the scrolling to only scroll down and not up in vertical mode.
+3
Khushal dugar
source
to share
1 answer
Decision
Subclass UIScrollView and override the methods to limit horizontal scrolling and scroll down only:
class DownwardsOnlyScrollView: UIScrollView
{
override func setContentOffset(_ contentOffset: CGPoint, animated: Bool) {
// restrict movement to vertical only
let newOffset = CGPoint(x: 0, y: contentOffset.y)
//only scroll if scroll direction is downwards
if newOffset.y > self.contentOffset.y
{
super.setContentOffset(newOffset, animated: animated)
}
}
}
0
torinpitchers
source
to share