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?
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.
I got exactly the same problem and the only workaround I found so far was to do performSelector:withObject:afterDelay - to set the contentSize property after some small delay: UIScrollView won't scroll even when I set content size
精彩评论