I've a scrollview and i want that scrollview to only scroll downwards and it should not scroll in any other direction. It is not about horizontal or vertical but that I want the scrollview to scroll only downwards and not upwards in vertical mode.
Asked
Active
Viewed 956 times
3
-
You need to set scrollView.contentSize larger than its frame size for scrolling. If you want horizontal scrolling, set contentSize's width larger than frame width. – nynohu May 12 '17 at 07:53
-
possible duplicate of http://stackoverflow.com/questions/5370428/uiscrollview-disable-scrolling-in-just-one-direction – user3581248 May 12 '17 at 08:24
1 Answers
1
Solution
Subclass UIScrollView and override the methods to restrict horizontal scrolling and only scroll if direction is downwards:
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)
}
}
}

torinpitchers
- 1,282
- 7
- 13
-
1Why would you want to only scroll downwards and not let the user scroll back up? That's a very bad UI Decision, Apple guidelines state that "The User should always be in control not the app". By not allowing them to scroll up you are taking the control away from the user. – torinpitchers May 12 '17 at 08:48
-
The user will be able to scroll up by using a button and not by scrolling. – Khushal Dugar May 12 '17 at 08:57
-
-