Swift -- When removing UIView (animated) it stays on screen

140 Views Asked by At

I have the following code in Swift. The problem is when it is executed, it performs the animation, but the window stays in its original position as shown in the gif I attached.

UIView.animateKeyframes(withDuration: 0.5, delay: 0, options: .calculationModePaced, animations: {
    self.view.viewWithTag(123)?.frame = CGRect(x: screenWidth5/2, y: screenHeight, width: screenWidth5 * 4, height: screenHeight5 * 3 )
}, completion: .none)

self.view.viewWithTag(123)?.removeFromSuperview()

Thank you for your time and answers.

1

There are 1 best solutions below

0
aheze On

You need to put removeFromSuperview in your completion handler.

UIView.animateKeyframes(withDuration: 0.5, delay: 0, options: .calculationModePaced, animations: {
    self.view.viewWithTag(123)?.frame = CGRect(x: screenWidth5/2, y: screenHeight, width: screenWidth5 * 4, height: screenHeight5 * 3 )
}) { _ in
    self.view.viewWithTag(123)?.removeFromSuperview()
}