简体   繁体   English

Swift——当移除 UIView(动画)时,它会停留在屏幕上

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

I have the following code in Swift.我在 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.问题是当它被执行时,它执行动画,但窗口保持在它的原始位置,如我附加的 gif 所示。

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.您需要将removeFromSuperview放在完成处理程序中。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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