Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting the content size of my UIScrollView in viewDidLoad/viewWillAppear has no effect - why?

I'm trying to force the content size of my UIScrollVIew when it's container loads. I'm finding this much more difficult than I'd imagine it would be. I've tried setting the content size in both viewDidLoad and viewWillAppear, like so:

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

If I place a breakpoint right after I call setContentSize, I can see that the new content size is indeed what I set it to.

However, if I then check the content size at some arbitrary point after viewWillAppear, such as, say, scrollViewDidScroll, the content size has reverted back to the size of the "actual" content in the scroll view, and not the size I tried forcing it to be in viewDidAppear.

Why is this?

like image 775
Rob Avatar asked Feb 23 '23 06:02

Rob


1 Answers

I have no idea what is resetting it on you, but I can help you find the answer.

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

like image 107
Anomie Avatar answered Mar 09 '23 01:03

Anomie