0
votes

I have a scrollview where I dynamically adjust its contentSize depending on what content is in the scrollview. The problem is that after having done all the adjustments it is not scrolled to the top. I tried with setting the contentOffset to 0,0 but that did not work as well.

I am using storyboard.. any idea what this could be?

Here some code

[scrollView setScrollEnabled:YES];
[scrollView setContentSize:CGSizeMake(320, 700)];
[scrollView setBackgroundColor:[UIColor colorWithRed:0.892 green:0.893 blue:0.892 alpha:1.0]];

Move the labels

// Move Description Label / Image
self.descriptionImageView.frame = CGRectMake(20, self.importantInfo.frame.origin.y + self.importantInfo.frame.size.height + 20, self.descriptionImageView.frame.size.width, descriptionImageView.frame.size.height);
self.descriptionLabel.frame = CGRectMake(self.descriptionImageView.frame.origin.x + self.descriptionImageView.frame.size.height + 20, self.importantInfo.frame.origin.y + self.importantInfo.frame.size.height + 20, self.descriptionLabel.frame.size.width, self.descriptionLabel.frame.size.height);

// Adjust scroll size so it does not scroll out the content
[scrollView setContentSize:CGSizeMake(scrollView.contentSize.width, description.frame.origin.y + description.frame.size.height + 20)];

enter image description here

1
Can you print the frame of the scrollview to debug?Mathieu Hausherr
got it working by deleting the scrollview and adding a new one with the exact same numbers... somewhere it kept the reference with a height of 460... thanks for the hint! You should create an answer so I can mark it as answered.Chris

1 Answers

0
votes

You should make sure that the UIScrollView is positioned and sized correctly.

Try to position it at x: 0 and y: 44. And set the height of it to be 436 px.

Let me know if it works :)