-1

I would like to achieve the following functionality. I have an UITableView which consists of UitableViewCells with images of various heights. When i slide up with my finger i need to stick the next UITableViewCell that comes up from the bottom to the top of the UITableView. If i scroll again i need the next UITableViewCell to stop to the top of UITableView and so on. If i slide down the previous UITableViewCell should stick to top and so on. How can i achieve this functionality? Any example or help appreciated.

stefanosn
  • 3,264
  • 10
  • 53
  • 79
  • Does this answer your question? [UIScrollView custom paging size](https://stackoverflow.com/questions/6813270/uiscrollview-custom-paging-size) – Cy-4AH May 23 '22 at 11:53
  • Not really clear... are you saying that *as you drag the touch* you want the table view "snapping"? Or, continuous scroll as you drag, but then some sort of "snap to position" when touch ends? Or, do you want every cell to act like a section header in a multi-section table view? – DonMag May 23 '22 at 12:58
  • @DonMag Hello sir thanks for responding i appreciate it, please let me explain better the following behaviour. I have a uitableview with one section. I have 5 uitableviewcells. Each one of them has an image inside. When the uitableview shows up i see the first uitableviewcell image in full screen. If i slide with my finger (scroll) up then the second uitableviewcell should come up as usual scroll behaves but the uitableviewcell scrolling should stop when it reaches on top of uitableview... – stefanosn May 23 '22 at 13:24
  • @stefanosn - if you only have 5 cells (images), and each cell is "full screen" ... you're not really using much in the way of table view functionality. Easier ways to do that, including a `UIScrollView` with paging enabled... a vertical `UIPageViewController` ... etc. Is there a specific reason you want to use a table view? – DonMag May 23 '22 at 13:48
  • There is already a UIScrollView to the UITableView i use. I just want to find a solution with minimal changes. So i should use the UIScrollView paging enabled property? – stefanosn May 23 '22 at 13:56
  • @stefanosn - you really need to describe ***in detail*** what you're trying to do. You're post says *"UitableViewCells with images of various heights"* ... so what should happen if you've scrolled up just a little? or a lot? What if 3 of the cells are short enough so they are all visible at the same time? – DonMag May 23 '22 at 17:13
  • @DonMag If the UITableViewCell images has different sizes there will be black gaps at above and below of the uitableviewcell and the image will be centered to the uitableviewcell height. UItableviewcell height should fill the screen of the device. If you scroll up just a little or a lot does not matter. In both cases the next custom cell image should show up to the user. If three cells are short enough again the first cell image will be centered and the cell should take up the height of the screen filling the gaps above the image with black and below the image as well with black color... – stefanosn May 23 '22 at 17:54
  • @stefanosn - if you set the `.rowHeight` to the table view's frame height, and set `tableView.pagingEnabled = YES;`, does that give you what you're going for? – DonMag May 23 '22 at 19:13
  • I will check and let you know – stefanosn May 23 '22 at 19:16

1 Answers1

0

You can achieve this using paging in UICollectionView