Disabling vertical scrolling in UIScrollView
yes, pt2ph8's answer is right,
but if for some strange reason your contentSize should be higher than the UIScrollView, you can disable the vertical scrolling implementing the UIScrollView protocol method
-(void)scrollViewDidScroll:(UIScrollView *)aScrollView;
just add this in your UIViewController
float oldY; // here or better in .h interface
- (void)scrollViewDidScroll:(UIScrollView *)aScrollView
{
[aScrollView setContentOffset: CGPointMake(aScrollView.contentOffset.x, oldY)];
// or if you are sure you wanna it always on top:
// [aScrollView setContentOffset: CGPointMake(aScrollView.contentOffset.x, 0)];
}
it's just the method called when the user scroll your UIScrollView, and doing so you force the content of it to have always the same .y
Try setting the contentSize's height to the scrollView's height. Then the vertical scroll should be disabled because there would be nothing to scroll vertically.
scrollView.contentSize = CGSizeMake(scrollView.contentSize.width,scrollView.frame.size.height);
Include the following method
-(void)viewDidLayoutSubviews{
self.automaticallyAdjustsScrollViewInsets = NO;
}
and set the content size width of the scroll view equal to the width of the scroll view.
since iOS7:
first: the content size width must be equal to the width of your scrollview
second: in your initWithNibName:
self.automaticallyAdjustsScrollViewInsets = NO;
That´s it.