ios - Swift——删除 UIView(动画)时,它会留在屏幕上
问题描述
我在 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()
感谢您的时间和回答。
解决方案
您需要放入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()
}
推荐阅读
- python - 如何矢量化涉及 python 中 type() 函数的 for 循环操作
- c# - EF.Core 迁移 - 具有继承类 ID 的抽象类关系
- swagger - nestjs 招摇默认 apiproperty 到当前日期
- java - 我可以使用 JPA 存储库查询将元素添加/插入到我的 ElementCollection 中吗?
- server - 为什么Installshield在2019 Datacenter上卸载时不删除服务,即在域上
- lastpass - 如何在 LastPass 中查找所有包含文件/附件的记录?
- java - 为什么在 Java 中使用实例变量时要声明(最终)局部变量?
- vb.net - vb.net - TCP 发送器/侦听器不能在单台机器之外工作
- json - 将标准 JSON 插入 DynamoDB aws-sdk js v3
- python - 将Json数据加载到python中的数据框中