0
votes

I got a weird bug. I have a UIViewController with a UIScrollView embedded inside the UIView. Inside the UIScrollview are few images, but I need more space, so I want to put some images under the current ones. I did all the usual stuff to create and initialize my ScrollView, but instead of scrolling in the UP/DOWN direction, it scrolls LEFT/RIGHT … What is going on?

  • I declared "UIScrollViewDelegate" in the .h
  • My property @property (weak, nonatomic) IBOutlet UIScrollView *scrollViewContent; is connected to my scrollview in IB

  • My ContentSize is declared as: self.scrollViewContent.contentSize= CGSizeMake(self.scrollViewContent.frame.size.width, 1000); and whether I declare it in ViewDidLoad or viewDidLayoutSubviews doesn't change anything.

  • I set self.scrollViewContent.delegate = self; in ViewDidLoad

UPDATE

Interestingly enough, I tried setting the ContentSize and then printing it to the console. As it turns out, the "Height" attribute always returns 0. Also, note that I set the "Width" to 1500, but it prints 2000. I'm not using auto-layout.

 [self.scrollViewContent setContentSize:CGSizeMake(1500, 2000)];

    NSLog(@"contentSize width %f", self.scrollViewContent.contentSize.width);
    NSLog(@"contentSize height %f", self.scrollViewContent.contentSize.height);

Result:

"contentSize width 2000.000000" "contentSize height 0.000000"

UPDATE 2 If I take the exact same Code and the exact same Xib in another project, it works just fine… what is wrong with my actual project?

1
You need to show a little more code than that. - fzwo
That's all the code I have. The images are Set up in Interface Builder - anthoprotic
Am I understand correctly, you set contentSize and then immediately, on the next line of code read it back and this gives you different value? Are you using standard scroll view or subclass of it? - yurish
Please log your scrollView transform. - fzwo
@yurish exactly. Note that I used the exact same code in another project and it works perfectly. - anthoprotic

1 Answers

0
votes

Please check properties as shown in image

Please cross check that you declared

UIScrollViewDelegate at .h file or not..

At .m File

@synthesize scrollViewContent;

Hope it may help you...