So I tried multiple animation functions but what you basically need is two animations, one for up and one for down. I came up with this code, where it uses keyframe animation.
[UIView animateKeyframesWithDuration:1.0 delay:0.6 options:UIViewKeyframeAnimationOptionCalculationModeCubicPaced animations:^{
// scroll up in 40% of the duration
[UIView addKeyframeWithRelativeStartTime:0 relativeDuration:0.4 animations:^{
NSIndexPath *scrollIndexPath = [NSIndexPath indexPathForRow:1 inSection:0];
[self.tableView scrollToRowAtIndexPath:scrollIndexPath atScrollPosition:UITableViewScrollPositionTop animated:NO];
}];
// scroll down starting at 40% of the duration until the end of the duration
[UIView addKeyframeWithRelativeStartTime:0.4 relativeDuration:0.6 animations:^{
NSIndexPath *scrollIndexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView scrollToRowAtIndexPath:scrollIndexPath atScrollPosition:UITableViewScrollPositionTop animated:NO];
}];
} completion:^(BOOL finished) {
NSLog(@"Animation complete!");
}];
You can tweak your animation with different times to produce a result more to your liking, but be aware that in the function addKeyframeWithRelativeStartTime: relativeDuration: animations:
the start time and duration are relative so a value from 0.0 to 1.0 of the whole duration which is specified in the animateKeyframesWithDuration: delay: options: animations:
.
Usually you would call this when the data in the tableView is loaded. Also you would then need to add a check if it is first time (stored in the NSUserDefaults).
--
EDIT:
If you want to scroll just a bit, specified by number of points, and not for the whole item row, you can also use:
[self.tableView setContentOffset:CGPointMake(0.0, 10.0)];
and
[self.tableView setContentOffset:CGPointMake(0.0, 0.0)];
respectfully.
This also works for a collection view and you can also scroll horizontally or diagonally (depending on how you set the coordinates).