1

I've been banging my head against the wall for the last hour trying to get my scrollView to scroll, but to no avail. In viewDidLoad I have

  NSURL *url = [FlickrFetcher urlForPhoto:self.photoData format:FlickrPhotoFormatLarge];
  NSData *imageRawData = [NSData dataWithContentsOfURL:url];
  UIImage *image = [UIImage imageWithData:imageRawData];

  self.scrollView.delegate = self;
  self.imageView.image = image;
  self.scrollView.contentSize = image.size;
  self.imageView.frame = CGRectMake(0, 0, image.size.width, image.size.height);

I have the imageView view mode set to top left.

My UIScrollView was created by selecting my imageView, then Editor -> Embed in -> ScrollView.

Anything else I can check/try?

Bill
  • 3,584
  • 5
  • 35
  • 47

3 Answers3

3

If you have created your scrollview through nib, and if that nib has autolayout feature then it will not let you scroll.

So go utility window of nib.
Select First tab of utility window.
Remove autolayout and run the application
Sunil Pandey
  • 7,042
  • 7
  • 35
  • 48
  • i will have to find why this is happening – Sunil Pandey Dec 13 '12 at 09:05
  • This sounds like it could be it... I'm trying to find the utility window, but no luck. FWIW, I'm using the latest version of xcode & created my scrollview via a storyboard. – Bill Dec 13 '12 at 15:53
  • Autolayout was the issue. I didn't understand his description at first. Basically, selecting your storyboard, then the File Inspector (first tab) & uncheck "Use Autolayout" – Bill Dec 15 '12 at 02:35
  • Anyone know WHY this is the case? I can't find that out anywhere. – James Jun 26 '14 at 18:43
0

Checklist:

  1. Is image really downloaded? (so it actaullly has size?)
  2. Is scrollview outlet set?
  3. Is imageView added as a subview of scrollView?

Btw. Don't know if this is just sample code or real but if it's real then it's really bad idea to download data synchronously and even worse idea to do it in viewDidLoad.

Michal
  • 961
  • 1
  • 12
  • 19
  • Yes to all. The image will show (just not scroll). (And agree on downloading in viewDidLoad. I'm just going through the Stanford class. This becomes multi-threaded in the next assignment.) – Bill Dec 13 '12 at 08:36
0

I guess it because you have image view embedded in scrollview,so its frame is becoming to imageview's frame. when frame size and content size are equal, scrollview wont scroll. Try setting scrollview's frame pragmatically to some fixed rectangle. ScrollView's contentSize's height and width should be greater then scrollview's frame's height and width. Give it some space to scroll:) In your case , they both are equal I guess.

Vishal Singh
  • 4,400
  • 4
  • 27
  • 43
  • Ah, I thought this might be it. I tried logging both & it looks like they are sized differently: – Bill Dec 14 '12 at 18:34
  • 2012-12-14 10:33:35.909 SimpleScrollView[3439:c07] scrollView contentSize: 3264.000000 x 2448.000000 2012-12-14 10:33:35.909 SimpleScrollView[3439:c07] scrollView frame: 320.000000 x 460.000000 – Bill Dec 14 '12 at 18:34