Bill
Bill

Reputation: 3672

In iOS6, XCode 4.5, UIScrollView is not Scrolling, despite contentSize being set

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?

Upvotes: 1

Views: 1852

Answers (3)

Vishal Singh
Vishal Singh

Reputation: 4490

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.

Upvotes: 0

Sunil Pandey
Sunil Pandey

Reputation: 7102

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

Upvotes: 3

Michal
Michal

Reputation: 971

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.

Upvotes: 0

Related Questions