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

旧巷老猫 提交于 2019-12-24 13:06:55

问题


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?


回答1:


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



回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/13855810/in-ios6-xcode-4-5-uiscrollview-is-not-scrolling-despite-contentsize-being-set

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!