【发布时间】:2016-04-22 08:16:12
【问题描述】:
我正在开发一个允许用户下棋的项目。我有一个代表板的父视图,每个方块都作为子视图添加到板上。棋子是一个 UIImageView 并作为子视图添加到正方形中。
occupyingPieceImageView = UIImageView(frame: CGRectMake(0, 0, size, size))
self.addSubview(occupyingPieceImageView)
要为国际象棋移动设置动画,我想将棋子的位置从一个正方形更改为另一个,我知道这意味着更改 UIImageView 的框架但我不知道如何,该框架仅在它的父视图内(正方形)。这不起作用:
func move(destSquare: Square){
var imgView = self.occupyingPieceImageView
var thisPiece = self.piece
UIView.animateWithDuration(3, animations: {
self.clearPiece()
imgView.frame = destSquare.frame
})
destSquare.setPiece(thisPiece)
}
【问题讨论】:
标签: ios swift animation uiimageview