Koloda
Koloda copied to clipboard
Animation defects
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()
When the animation is halfway, func koloda(_ koloda: KolodaView, didSwipeCardAt index: Int, in direction: SwipeResultDirection)
UIView animation can solve this problem, I hope not to use pop
I also hope to use UIView animation
+1