Mine was pretty simple. Just create two boolean checks to see if it is swiping left or right and then reset the frame based on which condition was triggered:
fileprivate func handleEnded(_ gesture: UIPanGestureRecognizer) {
let shouldDismissCardRight = gesture.translation(in: nil).x > threshold
let shouldDismissCardLeft = gesture.translation(in: nil).x < threshold * -1
UIView.animate(withDuration: 0.75, delay: 0, usingSpringWithDamping: 0.6, initialSpringVelocity: 0.1, options: .curveEaseOut, animations: {
if shouldDismissCardRight {
self.frame = CGRect(x: 1000, y: 0, width: self.frame.width, height: self.frame.height)
} else if shouldDismissCardLeft {
self.frame = CGRect(x: -1000, y: 0, width: self.frame.width, height: self.frame.height)
} else {
self.transform = .identity
}
}) { (_) in
self.transform = .identity
self.frame = CGRect(x: 0, y: 0, width: self.superview!.frame.width, height: self.superview!.frame.height)
}
}