UICollectionView not scrolling (jumping) when removing 2nd of 2 item

UICollectionView don't animate when removing 2nd item of 2 total, just jumps after pre-last item disappear.



UICollectionView animates add/remove item fine in all other cases (works fine for deleting 3rd of 3, 4th of 4, 15th of 15 etc) excepting the situation when you try to remove 2nd of 2 item. Have no idea why, does anyone can help me to solve that? Please watch the short video. You can try the ready project as well.



***Custom FlowLayout is must have, no chance to remove it.


Video explanation

https://vimeo.com/390343515


Sample project on GitHub

https://github.com/mrbodich/Test-Collectionview



Thank you for any help

Replies

Video does not show a lot. All pages are yellow. What are we supposed to notice ?

Look at the animation when I am removing cards. When I remove 2nd card (and 2 cards total left!) animation is not smooth. Card is disappear and after that scroll position jumps to the single card left. I've turned on slow animations in the end of the video to make it super easy to notice.

No matter cards are just yellow, you should look on scroll position and card disappearing animations only.

Tell me please if you see what I am talking about now.

OK. That would be easier to see with different colors, but I think I got it.

I have adapted code to make it easier to notice


    override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CollectionViewCell", for: indexPath)
        switch indexPath.row {
        case 0: cell.backgroundColor = .blue
        case 1: cell.backgroundColor = .green
        case 2: cell.backgroundColor = .yellow
        case 3: cell.backgroundColor = .orange
        case 4: cell.backgroundColor = .red
        case 5: cell.backgroundColor = .purple
        default: cell.backgroundColor = .yellow
        }
        return cell
    }

When you remove 3rd on 3, or 4 on 4, there is a flip effect.

Not when you remove the 2nd out of 2.


I think it is a 'normal' behavior.


When you have 3 cards, and remove 3rd, you can swipe n°2 in place of 3 and n°1 in place of 2 (we see it on screen).

But when there are only 2 left, and remove the second you could swipe n°1 in place of 1 but there is nothing to move in place of n°1.

Hence animation cannot start and is replaced by a simple substitution.


Could ask support for confirmation if that is really important for you.

No, actually as I see it, here is how it works. Not sure why you saying it's swiping there (or maybe I misunderstood you).


When you remove the last card (and have more than 2 cards total), we have 2 animations at the same time:

  1. Card alpha from 1 to 0, so it bacame invisible
  2. collectionView's contentOffset animates to the previous card that is going to be last.


When we have 2 cards total and removing the last we have these animations:

  1. Card alpha from 1 to 0, so it bacame invisible
  2. collectionView's contentOffset animates to the previous card that is going to be last. — This animation just don't work and when disappearing card disappears entirely, contentOffset just jumps where it should be without animation.


It looks like an old Apple's bug. I've seen the same question 5 years old and this behavior was not solved yet.

Unfortunately I cannot ask support because I don't have a paid developer account for now :((( I am in the process creating my first serious app. Will buy pro right before sending to AppStore.

Swipe meant that card slides with animation in place of the removed one.


So we say essentially the same thing.


That's not really a serious issue (in my mind) for user ; in fact we could even consider that's a way to notify there is just 1 card bleft.


But feel free to ask for enhancement once you have your developer account (not sure they will care on it …)

Oh, yes, it’s swiping when you remove not the last card) But when you are removing the last one (the last index in row I mean), it’s just disappearing, not swiping because it’s the last index))) In my opinion it’s just terrible UI bug, I am crying when looking at it... Will report once will get a paid subscription. Thanks for the conversation:)