Setting the size of the contents of my UIScrollView in viewDidLoad / viewWillAppear does not affect - why?

I am trying to force the content size of my UIScrollVIew when loading a container. I find it a lot harder than I guess. I tried to set the content size in both viewDidLoad and viewWillAppear , for example:

 -(void)viewWillAppear:(BOOL)animated { CGSize newContentSize = CGSizeMake(scrollView.contentSize.width, scrollView.frame.size.height + 80.0); [scrollView setContentSize:newContentSize]; } 

If I set a breakpoint immediately after calling setContentSize , I see that the new content size is really what I set it to.

However, if I then check the size of the content at some arbitrary point after viewWillAppear , for example, scrollViewDidScroll , the size of the content will return to the size of the "actual" content in the scroll, and not the size that I tried to force it to be in viewDidAppear .

Why is this?

+4
source share
2 answers

I have no idea what restarts it, but I can help you find the answer.

What I usually do in this situation is to subclass UIScrollView (usually like "XXXUIScrollView"), override setContentSize: (just call [super setContentSize:size] , possibly with NSLog) and set a breakpoint in the overridden method, see that sets the value.

+8
source

I had the same problem, and the only workaround I have found so far was to make performSelector: withObject: afterDelay - set the contentSize property after a short delay: UIScrollView will not scroll even if I set the content size

0
source

All Articles