嘿,我想创建一个集合游戏应用程序,现在我想把我的卡片(UIViews)移到newPosition上。动画结束后,我希望此视图从超级视图中删除
func btnUp(card: CardSubview, frame: CGRect) {
let newPosition = CGRect(x: (self.superview?.frame.minX)!, y: (self.superview?.frame.maxY)!, width: card.bounds.width, height: card.bounds.height)
//UIView.animate(withDuration: 3.0, animations: {card.frame = newPosition})
UIView.animate(withDuration: 3.0, animations: {card.frame = newPosition}, completion: {if card.frame == newPosition {card.removeFromSuperview()}})
}
这是有效的,但如果我想添加一个补全,我会得到这个错误:
无法将类型为'() -> ()‘的值转换为预期的参数类型'((Bool) -> Void)?'**
那么我到底做错了什么?
发布于 2018-05-28 18:19:35
完成
动画序列结束时要执行的块对象。此块没有返回值,只接受一个布尔参数,该参数指示动画是否在调用完成处理程序之前实际完成。
因此,您需要将布尔参数提供给完成处理程序:
UIView.animate(withDuration: 3.0, animations: {card.frame = newPosition}, completion: { finish in
if card.frame == newPosition {
card.removeFromSuperview()
}
})
发布于 2018-05-28 18:13:57
试试这个:
您需要设置completion block
变量
func btnUp(card: CardSubview, frame: CGRect) {
let newPosition = CGRect(x: (self.superview?.frame.minX)!, y: (self.superview?.frame.maxY)!, width: card.bounds.width, height: card.bounds.height)
//UIView.animate(withDuration: 3.0, animations: {card.frame = newPosition})
UIView.animate(withDuration: 3.0, animations: {
card.frame = newPosition
}, completion: { finish in
if card.frame == newPosition {card.removeFromSuperview()
}})
}
发布于 2018-05-28 18:15:34
UIView.animate(withDuration: 0.25, animations: {
view.transform = CGAffineTransform(translationX: view.frame.maxX, y: 0)
},completion:{(completed:Bool) in
if(completed){view.removeFromSuperview()}
})
https://stackoverflow.com/questions/50563978
复制相似问题