0

I am currently in the process of creating a UITableView with a UITableViewHeader. This UITableViewHeader is a HeaderView for the first section of my UITableView which has the ability to expand or collapse. It shows filters to narrow down what is shown in the UITableView.

It currently all works great, expanding the UITableViewHeader works nicely, but as soon as I collapse the UITableViewHeader (I animate two bottom constraints to true & false to collapse the UITableViewHeader), the cells that are not visible at first (so the ones that are off-screen) don't animate, they just "come in place" as soon as I hit the button.

I am now wondering if it is possible to make sure these cells also follow the animation, so they kind of "slide up" from underneath the bottom of the screen rather than just fall in place directly. The animation takes 0.25 seconds, so the cells are visible 0.25 seconds too soon let's say.

Any ideas?

PennyWise
  • 595
  • 2
  • 12
  • 37
  • Have you considered using `tableView.scrollToRow(ar: IndexPath (row: 0, section: 0), at: .top, animated: true)`? Noting that conflicting animations will cancel out - IIRC the latest to commence will override any already underway. – andrewbuilder Apr 30 '19 at 21:01
  • I’ll tale a look at this now. Thanks for the idea. – PennyWise Apr 30 '19 at 21:13
  • Edit `scrollToRow(at: IndexPath`... – andrewbuilder Apr 30 '19 at 21:17
  • It doesn't work. I mean, it probably scrolls to the first row and all, but the existing "animation" remains the same. I mean, the animation I want doesn't occur. – PennyWise May 01 '19 at 11:44
  • Also, exact same behavior as what I am experiencing in [this post](https://stackoverflow.com/questions/41933077/cells-disappearing-during-animation-of-uitableview). – PennyWise May 01 '19 at 11:45
  • I'm stretching my `.bounds` and `.frame` memory and I don't know this for certain, but is it worth thinking about enlarging the tableView's frame off screen (from the bottom edge) by an amount that equals the height of your `UITableViewHeader`, either just before you contract the size of the header or, alternatively on a permanent basis (programmatically or in a storyboard/IB)? – andrewbuilder May 01 '19 at 12:46

1 Answers1

0

It's hard to say without seeing any of your code or a gif that captures the problem.

When you say that the cells are "off-screen", are they hidden, are their frames updated or do they have any translation transforms applied?

Before you collapse your UITableViewHeader, the cells have to move off-screen by either having their frames modified (so for example, their y is equal to the height of your view, placing them right at the bottom, below your visible view) or having translation transforms applied. Then, when you collapse your UITableViewHeader, you'll have to 'slide them up' by modifying their position - either by changing their frame origin or by applying a translation transform (or identity transform, depending on what transform you begin with). Keep in mind that this advice is kind of a shot in the dark without knowing the specific details of your problem.

nambatee
  • 1,478
  • 16
  • 27
  • With off screen I mean there are for example 20 cells but only 8 fit in the current visible view, so the remaining 12 are off screen. The first 8 animate with the updating bottom anchor, so they move up or their y-position is updated along the .25 seconds. The other 12 don’t and just fall into place immediately. – PennyWise Apr 30 '19 at 21:13
  • Might be helpful: [this post](https://stackoverflow.com/questions/41933077/cells-disappearing-during-animation-of-uitableview) has the exact same issue as I have and there is a GIF. – PennyWise May 01 '19 at 11:46