Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIScrollView resetting contentOffset

I have a UIScrollView whose content offset resets itself all the time for some random reason. Has anyone ever encountered this issue? I had the content offset to 100 and then it resets back scrolling to the top. Any way to prevent this?

So here's the code/hack that I did to make it work in setting the contentOffset:

 [self.currentViewController_ performSelector:@selector(scrollToOffset:) withObject:nil afterDelay:0.1];

and in my currentViewController class I have

-(void)scrollToOffset: (CGFloat) yOffset
{
    [[self.webView_ defaultScrollView] setContentOffset:CGPointMake(0, -44) animated:YES];
}
like image 544
xonegirlz Avatar asked Mar 13 '12 22:03

xonegirlz


1 Answers

I had a similiar problem. In my case, the problem was that I set the content size of the scrollview in viewDidLayoutSubviews. When I tried to scroll the view back programatically, viewDidLayoutSubviews was called and this caused a reset of the content size.

like image 93
Oliver Avatar answered Oct 04 '22 08:10

Oliver