Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot Scroll UIScrollView

I've got a UIScrollView in IB linked to the delegate and with the proper referencing outlet, declared in my header:

IBOutlet UIScrollView *scrollView;

And called in my viewDidLoad:

- (void)viewDidLoad
{
    [super viewDidLoad];
    [scrollView setScrollEnabled:YES];
    [scrollView setContentSize:CGSizeMake(320, 500)];
}

It has the correct size and width in IB, and the default values in the Attributes inspector.

Why can't I scroll it?

EDIT: Also, layer wise there is no other view conflicting for a z-index.

like image 391
Peter Kazazes Avatar asked Aug 09 '11 01:08

Peter Kazazes


3 Answers

Is the content size larger than the scrollview's frame? That's the only way it'll scroll.

like image 77
mjisrawi Avatar answered Nov 09 '22 07:11

mjisrawi


Double-check that you have content size bigger than scroll view size itself. If it will be bigger it will scroll.

like image 40
Nikita Leonov Avatar answered Nov 09 '22 07:11

Nikita Leonov


m using Xcode 6/iOS 8+ now with auto-layout turned on, and I had the same problem in the first place, removing auto-layout doesn't work at all, so in order to make scroll view scrollable vertically, I made sure the following:

  1. The scroll view content size height MUST be bigger than the screen height, this almost goes without saying...
  2. The top/bottom/left/right constraint of the scroll view HAS TO BE pinned, I did this using storyboard so no code showing up here

If you want to make the scroll view scrollable horizontally, then make sure its content size width is bigger than the screen width, the other rule applies the same.

This worked for me, hope it can help someone.

like image 2
dulan Avatar answered Nov 09 '22 06:11

dulan