JoniVR / VerticalCardSwiper

A marriage between the Shazam Discover UI and Tinder, built with UICollectionView in Swift.
MIT License
1.39k stars 100 forks source link

[Bug] `scrollToCard` animation doesn't look right with custom duration #60

Open MateuszW13 opened 4 years ago

MateuszW13 commented 4 years ago

New Issue Checklist

Question

Is it possible to slow down the animation of scrollToCard(at:animated) method ? I was trying to slow it done with:

UIView.animate(withDuration: 2.0, animations: {
         self.view.setContentOffset(point, animated: false)
 })

and

UIView.animate(withDuration: 2.0, animations: {
         self.view.scrollToCard(at: cards.count, animated: false)
 })

and both of the methods don't seem to work for me.

JoniVR commented 4 years ago

The reason why it probably doesn't do anything is because cards.count probably is out of bounds (zero based index in array so you have to do cards.count - 1, the underlying function actually checks for this and will not scroll if you're out of bounds.

That said, if you use it with UIView.animate it currently seems to be very buggy... like this:

ezgif com-video-to-gif so that's something that definitely needs fixing.

MateuszW13 commented 4 years ago

Yup, I came to this point as well. Is there any other way to reduce this animation speed or fix the buggy part ?

JoniVR commented 4 years ago

Apparently, using UIView.animate() doesn't work properly on a normal collectionview either. It has something to do with cell creation. Also, setting the animated parameter to false also doesn't execute the actual animation code, which is probably what's happening here.

Have you tried wrapping it inside a CATransaction? See this comment here: https://stackoverflow.com/a/16693712/6863743 It's in objective-c but shouldn't be hard to translate to swift.

edit: nvm probably won't work but worth a shot.

MateuszW13 commented 4 years ago

I have tried this solution as well and still it is not working :(