【问题标题】:Swift -- When removing UIView (animated) it stays on screenSwift——删除 UIView(动画)时,它会留在屏幕上
【发布时间】:2021-03-01 04:21:16
【问题描述】:

我在 Swift 中有以下代码。问题是当它执行时,它会执行动画,但窗口停留在其原始位置,如我附加的 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()

感谢您的时间和回答。

【问题讨论】:

    标签: ios swift uiview uiviewanimation uiviewanimationtransition


    【解决方案1】:

    您需要将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()
    }            
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多