Lets say i have 10 rows displaying numbers 1 to 10. I need scrolling effect like 1 to 10 to 1to 10... I achieved this using scrollToRowAtIndexPath
and setContentOffset
. The issue i want to slow down the scrolling before i apply my logic to stop this recursion. So is there a way that i can decrease the scroll speed for scrollToRowAtIndexPath
.
? Please do not suggest, decelerationRate as scrolls here are all programmatic, no user interactions. Thanks in advance.
Asked
Active
Viewed 3,263 times
1

Avi
- 2,196
- 18
- 18
2 Answers
2
Just call your scrollToRowAtIndexPath or setContentOffset methods inside +(void)animateWithDuration:animations: block.
Check these answers for more details:
Change the speed of setContentOffset:animated:?
scrollToRowAtIndexPath:atScrollPosition:animated scrolling too slow

Community
- 1
- 1

Alex Kosyakov
- 2,095
- 1
- 17
- 25
1
You can do something like this:
[UIView animateWithDuration:durationInSeconds animations:^(void){
[tableView setContentOffset:offset animated:NO];
}];
You just need to calculate the offset. If your rows have equal heights, then your offset is simply calculated:
CGPoint offset = CGPointMake(0, indexPath.row * rowHeight);
and if the height varies then you need to do this:
CGFloat offsetY = 0;
for (NSInteger i = 0; i <= indexPath.row; i++) {
offsetY += [tableView.delegate tableView:tableView heightForRowAtIndexPath:indexPath];
}
CGPoint offset = CGPointMake(0, offsetY);
EDIT:
You can also use scrollToRowAtIndexPath:animated:
method with animated
set to NO
in the animation block instead of setContentOffset
, and then you don't have to calculate the offset yourself.

Frane Poljak
- 2,315
- 23
- 25
-
Sounds good. Do u mean that once i decide to slow down, i come out of my circular scroll recursion logic and do the above to reach my intended row which will give a slow scroll effect? – Avi Jun 04 '16 at 18:35
-
Yes, this is to slow down the scrolling, and you set the duration with 'durationInSeconds' parameter in animateWithDuration method. As Alex suggested in another answer, you can also use scrollToRowAtIndexPath:animated: method with animated set to NO in the animation block instead of setContentOffset, and then you don't have to calculate the offset yourself. – Frane Poljak Jun 05 '16 at 16:58
-
Yeah, Tried that. WOrks. – Avi Jun 05 '16 at 18:07