This is an interesting question. Have you seen this similar question on SO? It bounces vertically, not horizontally, but the concept is the same.
- Set pagingEnabled and scrollEnabled to NO
- Animate bounce using
scrollRectToVisible:animated:
- Set pagingEnabled and scrollEnabled back to YES
This discussion also has some sample code that may be useful.
EDIT:
I had a play around with the code in your edit above, and managed to get the bounce working in the correct direction. I had to use setContentOffset:animated:
instead of scrollRectToVisible:animated:
, and I also increased the timer interval to 0.3 (0.1 is not enough time for the bounce to reach the full distance before unbounceScrollView
is called).
My code in goLeftAction:
:
[self.scrollView setPagingEnabled:NO];
[self.scrollView setScrollEnabled:NO];
[NSTimer scheduledTimerWithTimeInterval:0.3 target:self selector:@selector(bounceScrollView) userInfo:nil repeats:NO];
The bounce methods:
- (void)bounceScrollView
{
[self.scrollView setContentOffset:CGPointMake(-100, 0) animated:YES];
[NSTimer scheduledTimerWithTimeInterval:0.3 target:self selector:@selector(unbounceScrollView) userInfo:nil repeats:NO];
}
- (void)unbounceScrollView
{
[self.scrollView setContentOffset:CGPointMake(0, 0) animated:YES];
[self.scrollView setPagingEnabled:YES];
[self.scrollView setScrollEnabled:YES];
}