0

I have a UITableView, and I don't want it to stop between two cells when it stops after scrolling. So I need to move the cell which is the nearest of the Y center of the screen, when the velocity of the UITableView is less than a given value.

I'm sure I'm not the first who wants this effect, but I didn't find anything in my research. There must be a word for this that I don't know. Does someone have a link or something ?

I tried to do this on my own, but I don't find how to get the cell. I used tableView.indexPathsForVisibleRows(), so I have an array of indexPaths, but now I don't know how to call the corresponding cell. There is cellForRowAtIndexPath, but this method creates a new cell, doesn't it ?

Vig
  • 1,532
  • 1
  • 12
  • 28
Morpheus
  • 1,189
  • 2
  • 11
  • 33

2 Answers2

2

You need to implement -scrollViewWillEndDragging:withVelocity:targetContentOffset: in your table view delegate, just as in this other question here.

Basically, this method allows you to tweak the position where the velocity scroll will halt.

I can't help you more with code without knowing the structure of your table view (cells of variable height?).

Community
  • 1
  • 1
Cyrille
  • 25,014
  • 12
  • 67
  • 90
  • I want the table view to decelerate after the end of the dragging, then move to the nearest cell when the velocity is less than a given value, is it possible with that function ? This function doesn't manage only what happen before the end of the dragging ? – Morpheus Nov 21 '14 at 15:55
  • This method allows to tweak the position where the scrolling will halt. It provides a much more natural scrolling, because the table view already knows where to stop before starting to scroll. There's no need to adjust the velocity, which would cause a visual speed increase or decrease. – Cyrille Nov 21 '14 at 15:56
  • My table view has cells of same height. But I want the cells to be bigger when they are "centered". In summary, I want a table view like in the "Storehouse" app for iPad. – Morpheus Nov 21 '14 at 15:59
  • Yep, you need a carousel, I understood that. If you want a "grow" effect for the center cell, I'd suggest you take a look at implementing a `UICollectionView` with a custom layout, that's precisely what it's meant to be used for. – Cyrille Nov 21 '14 at 16:02
  • Ok, I'm trying to use UICollectionView, I don't really understand customs layouts, but it seems to be the right way. Thanks for your help – Morpheus Nov 21 '14 at 17:57
  • Can you explain me quickly how should I implement the methods to have the carousel effect ? In which method should I change the size of the item ? Should I change the custom layout object or just directly the size of the item ? Thx – Morpheus Nov 21 '14 at 18:03
  • That's another question you should ask, after you've marked this one as answered or deleted it. – Cyrille Nov 21 '14 at 18:04
0

Try adding this to your ViewDidLoad:

self.tableView.bounces = false 
AMAN77
  • 6,218
  • 9
  • 45
  • 60