I\'ve been unable to find an answer for this (maybe someone has hacked a solution together).
Is it possible to disable scrolling in a UIScrollView in one direction?
Turn Off the auto layout. I had the same issues only fixed after disabling auto layout in the content view. Xcode 11 . Automatic -> Translate Masks to Constraints
Fortunately, we can use scrollRectToVisible to avoid jittery behavior after the scroll has been limited:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (scrollView.contentOffset.y > 60) {
[scrollView setContentOffset:CGPointMake(0, 60)];
CGFloat pageWidth = scrollView.frame.size.width;
CGFloat pageHeight = scrollView.frame.size.height;
CGRect rect = CGRectMake(0, 0, pageWidth, pageHeight);
[scrollView scrollRectToVisible:rect animated:YES];
}
}
This works for me:
-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
scrollView.bounces = YES;
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
if (scrollView.contentOffset.y < 0) {
[scrollView setContentOffset:CGPointMake(0, 0)];
scrollView.bounces = NO;
}
if (scrollView.contentOffset.y == 0){
scrollView.bounces = YES;
}
else scrollView.bounces = YES;
}
The above solutions will reset you to zero,zero if the user accidentally scrolls vertically. Try this...
- (void)scrollViewDidScroll:(UIScrollView *) scrollView {
if (scrollView.contentOffset.y > 0) {
[scrollView setContentOffset:CGPointMake(scrollView.contentOffset.x, 0)];
}
}