感谢阅读这篇文章。
这里是我的程序的总结:
我动态添加几个 UIView 作为 subview 。
我有四处移动和碰撞的物体
当发生碰撞时,我希望创建的 UIView 之一淡出,然后删除发生碰撞的 UIView 之一。
我可以使用以下命令删除创建的 UIView:
dynamicAnimator?.referenceView?.viewWithTag(tagOfView)?.removeFromSuperview()
但是,当我尝试添加动画来淡出 View 时,我没有得到任何类型的淡入/动画。我做错了什么?
UIView.animateWithDuration(1.5, animations: {
self.dynamicAnimator?.referenceView?.viewWithTag(tagOfView)?.alpha = 0.0
})
如果需要,这里是整个 collisionBehavior()
函数。
func collisionBehavior(behavior: UICollisionBehavior, beganContactForItem item: UIDynamicItem, withBoundaryIdentifier identifier: NSCopying, atPoint p: CGPoint) {
let identOpt : NSCopying? = identifier
if let ident = identOpt as? NSNumber {
switch ident {
case Identifiers.paddleAtStartup:
break
default:
ballCollider.removeBoundaryWithIdentifier(ident)
UIView.animateWithDuration(1.5, animations: {
self.dynamicAnimator?.referenceView?.viewWithTag(Int(ident))?.alpha = 0.0
})
dynamicAnimator?.referenceView?.viewWithTag(Int(ident))?.removeFromSuperview()
}
}
}
最佳答案
您在碰撞后立即移除 View ,并且没有任何动画。您最好在动画的完成处理程序中将其删除。
关于ios - 动态创建的 UIView 在碰撞后不会动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32571649/