嘿我想创建一套游戏应用程序,现在我希望我的卡片(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)?' **
所以我做错了什么?
答案 0 :(得分:1)
试试这个:
您需要设置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()
}})
}
答案 1 :(得分:1)
UIView.animate(withDuration: 0.25, animations: {
view.transform = CGAffineTransform(translationX: view.frame.maxX, y: 0)
},completion:{(completed:Bool) in
if(completed){view.removeFromSuperview()}
})
答案 2 :(得分:0)
<强>完成强>
动画序列结束时要执行的块对象。这个 block没有返回值,并且只接受一个布尔参数 表示动画是否真正在之前完成 完成处理程序被调用。
因此,您需要将该布尔参数赋予完成处理程序:
For i2 = 1 To 99
ModuleN = "B1M10"+i2
BeckDIE = ModuleN
BeckDIV = ModuleN
ExIntCellE = Sheets("Internal").Cells(RowStart + i2, EnableModify).Value
ExIntCellV = Sheets("Internal").Cells(RowStart + i2, ValueModify).Value
Config.Controls(BeckDIE).Enabled = ExIntCellE
Config.Controls(BeckDIV).Value = ExIntCellV
Next i2