Reputation: 8969
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];
}
Upvotes: 7
Views: 3825
Reputation: 5927
You can try stop the back animation when the first animation completes.
Use this delegate call:
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
And call this method inside it:
[self setContentOffset:self.contentOffset animated:NO];
Upvotes: 1
Reputation: 249
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.
Upvotes: 2
Reputation: 1074
Maybe problem in .contentSize property of your scrollView? Did you set it correct?
Upvotes: -1