marcosgriselli / ViewAnimator

ViewAnimator brings your UI to life with just one line
MIT License
7.3k stars 488 forks source link

Animation does not work for the bottom cells. #16

Closed alexanderkhitev closed 6 years ago

alexanderkhitev commented 6 years ago

Hello! There was a problem when using ViewAnimator and UIRefreshControl, that is, if for the first time the animation works as it should, then the second time after the data is reloaded with UIRefreshControl, the bottom three cells appear without animation. Of course, I understand that this is due to the fact that these cells are not visibleCells (at the start of the animation, 12 cells are visible, after the animation 15), but how to solve this problem?

Please see the video https://monosnap.com/file/CNs9V8EKIWbOsuLzXcybqfMRDb5jYp

Specifications

Update: At the moment I made a hack that I increase the CollectionView height to a value that helps to animate the lower row of cells, but there may be options to do it better.

marcosgriselli commented 6 years ago

@alexanderkhitev did you came up with a more complete solution? I'll be looking into this next.

alexanderkhitev commented 6 years ago

@marcosgriselli sorry for late response. I did not come up with a new solution, since I no longer work on that project.

marcosgriselli commented 6 years ago

0ef02e416f8b472196a969b2717d710cd547f91e adds the possibility of creating a straightforward fix for this kind of issues. We can now pass in the views we want to animate so we can get the visible cells and append the cell after the last visible one doing something like:

var cells = tableView.visibleCells
// Check if the refresh control is refreshing.
if let lastCell = visibleCells.last, let nextToLastIndexPath = collectionView.indexPath(for: lastCell) {
    if let nextToLastCell = collectionView.cellForItem(at: nextToLastIndexPath) {
        cells.append(nextToLastCell)
    }
}

UIView.animate(views: cells, animations: [scaleAnimation])