简体   繁体   中英

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

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.

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()
}            

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM