UIScrollView reset contentOffice
I have a UIScrollView whose content is shifting all the time for some random reason. Has anyone ever encountered this problem? I had the content offset to 100 and then it resets back the scroll to the top. Any way to prevent this?
So here is the code / hack I did to get it working in the contentOffset setting:
[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];
}
I had a similar problem. In my case, the problem was that I set the size of the scroll content in viewDidLayoutSubviews. When I tried to scroll the view backwards programmatically, the viewDidLayoutSubviews was called and this caused the content size to be reset.
You can stop the animation from stopping when the first animation ends.
Use this delegate call:
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
And call this method inside it:
[self setContentOffset:self.contentOffset animated:NO];
Could there be a problem with the .contentSize property of the scrollView? Have you installed it correctly?