2

I am following Paul Hegarty's 2012-2013 course in iTunes-u. In lesson 9 he gets the course to create a minimal app to display a photo on a UIScrollView. For him it worked first time. I thought I had copied the exercise exactly, but it has never scrolled for me.

The guts of code are this:

-(void)resetImage
{
    if (self.scrollView) {
        self.scrollView.contentSize = CGSizeZero;
        self.imageView = nil;

        UIImage *image = [UIImage imageNamed:@"photo_3.jpg"];
        if (image) {
            self.scrollView.contentSize = image.size;
            self.imageView.image = image;
            self.imageView.frame = CGRectMake(0, 0, image.size.width, image.size.height);
        }
    }
}

The image comes up and is fine in the simulator, but attempting to scroll has no effect. Can anyone suggest why scrolling doesn't work?

TIA Mark

MarkAurelius
  • 1,203
  • 1
  • 14
  • 27
  • What is the size of your image you are adding into scroll view? Is should be more than your screen visible area to have the scrolling effect. – Abhinav Oct 28 '13 at 04:18
  • 1
    disable AutoLayout and it will work – AJ112 Oct 28 '13 at 04:19
  • Thanks, AJ112. That got the scrolling happening. Now I just have to work out a less drastic way to do it. What it I am using auto layout in the rest of the project? – MarkAurelius Oct 28 '13 at 04:58
  • @AJ112: give it as an answer and Mark accept it, so that it can be useful to others. – Harikrishnan Oct 28 '13 at 05:02
  • Thanks for the advice, Harikrishnan. I tried to do that, but the only thing I see is the up arrow, which I clicked on. How do you promote a comment to an answer? – MarkAurelius Oct 28 '13 at 05:12
  • The problem I am having seems to be an echo of this one: http://stackoverflow.com/questions/18751742/uiscrollview-doesnt-scroll-after-upgrading-to-ios7-xcode-5 There doesn't seem to be a good solution yet. What I want is to have both scrolling and autolayout in the same project. – MarkAurelius Oct 28 '13 at 05:31
  • @MarkAurelius i have added it as an answer. I am unable to find any solution in which i keep both AutoLayout and scrolling enabled at the same time. It wasn't happening in iOS 6 so i ended up disabling the AutoLayout since i wasn't able to find any other solution – AJ112 Oct 28 '13 at 10:38

1 Answers1

1

I have the exact same issue. I tried everything but nothing worked for me. At last i have disabled the AutoLayout and it did start scrolling.

So just disable the AutoLayout and your ScrollView will start working.

AJ112
  • 5,291
  • 7
  • 45
  • 60
  • That works for the one UIViewController, but if you want to keep auto-layout on for the project, you can get it to work doing this: https://developer.apple.com/library/ios/technotes/tn2154/_index.html I tried the second one, and the problem I am having is that the top status bar gets covered by the image. It was easy to avoid that with the IB approach. – MarkAurelius Oct 28 '13 at 12:53