I have the following code to swipe a view out of the screen when swiped right
let gesture = UISwipeGestureRecognizer(target: self, action: #selector(swipedView(_:)))
gesture.direction = .right
centerView.addGestureRecognizer(gesture)
@objc func swipedView(_ sender: UISwipeGestureRecognizer) {
UIView.animate(withDuration: 2.0, animations: {
centerView.frame = centerView.frame.offsetBy(dx: self.view.frame.maxX-centerView.frame.minX, dy: 0)
}) { completed in
//Call API and if response failed move centerView to its original position
}
}
In animation's completion block I call an API. If the response is failed, I want to move centerView to its initial position. How can I do this without saving the starting frame in another variable?