Koloda icon indicating copy to clipboard operation
Koloda copied to clipboard

Animation defects

Open lixiang1994 opened this issue 7 years ago • 4 comments

suggest:

Don't use pop animation. It is based on CADisplayLink.

Because: completionBlock callback is not accurate.

use swipe(.left) When the animation is halfway, it will be called.

-> self.removeFromSuperview() -> layoutSubViews() -> layoutDeck() -> Animation is not smooth

e.g.

            let swipePositionAnimation = POPBasicAnimation(propertyNamed: kPOPLayerTranslationXY)
            swipePositionAnimation?.fromValue = NSValue(cgPoint:POPLayerGetTranslationXY(layer))
            swipePositionAnimation?.toValue = NSValue(cgPoint:animationPointForDirection(direction))
            swipePositionAnimation?.duration = cardSwipeActionAnimationDuration
            swipePositionAnimation?.completionBlock = {
                (_, _) in
                self.removeFromSuperview()
                completionHandler()
            }

            layer.pop_add(swipePositionAnimation, forKey: "swipePositionAnimation")
            let swipeRotationAnimation = POPBasicAnimation(propertyNamed: kPOPLayerRotation)
            swipeRotationAnimation?.fromValue = POPLayerGetRotationZ(layer)
            swipeRotationAnimation?.toValue = CGFloat(animationRotationForDirection(direction))
            swipeRotationAnimation?.duration = cardSwipeActionAnimationDuration

            layer.pop_add(swipeRotationAnimation, forKey: "swipeRotationAnimation")

            overlayView?.overlayState = direction
            let overlayAlphaAnimation = POPBasicAnimation(propertyNamed: kPOPViewAlpha)
            overlayAlphaAnimation?.toValue = 1.0
            overlayAlphaAnimation?.duration = cardSwipeActionAnimationDuration
            overlayView?.pop_add(overlayAlphaAnimation, forKey: "swipeOverlayAnimation")

to

            let target = animationPointForDirection(direction)
            CATransaction.begin()
            CATransaction.setCompletionBlock {
                self.removeFromSuperview()
                completionHandler()
            }
            UIView.beginAnimations("", context: nil)
            UIView.setAnimationDuration(cardSwipeActionAnimationDuration)
            let angle = animationRotationForDirection(direction)
            var transform = layer.transform
            transform = CATransform3DTranslate(transform, target.x, target.y, 0)
            transform = CATransform3DRotate(transform, angle, 0, 0, 1)
            layer.transform = transform
            overlayView?.overlayState = direction
            overlayView?.alpha = 1.0
            UIView.commitAnimations()
            CATransaction.commit()

lixiang1994 avatar Feb 01 '19 06:02 lixiang1994

wx20190201-145455 2x

When the animation is halfway, func koloda(_ koloda: KolodaView, didSwipeCardAt index: Int, in direction: SwipeResultDirection)

lixiang1994 avatar Feb 01 '19 06:02 lixiang1994

UIView animation can solve this problem, I hope not to use pop

lixiang1994 avatar Feb 01 '19 06:02 lixiang1994

I also hope to use UIView animation

brownsoo avatar Feb 01 '19 07:02 brownsoo

+1

hanawat avatar Feb 16 '20 09:02 hanawat