无法为UIImageview制作动画

时间:2017-07-06 11:10:49

标签: ios swift3 uiimageview

我的问题是,当我按下运行dealToPlayer功能()的按钮时,所有内容都表现为卡已经发出,更新了发牌的总价值,但它没有显示正在发牌的任何动画或放置。为什么会这样?我根本没有使用自动布局。

  func dealToPlayer() {

    let index = Int(arc4random_uniform(UInt32(deckCards.count)))
    let drawnCard = deckCards.remove(at: index)
    randomCards.append(drawnCard)


    randomCard = randomCards[3 + cardSelect]

    image = UIImageView(frame: CGRect(x: self.deckLocation.x, y: self.deckLocation.y, width: self.width, height: self.height))
    image.image = mapping[randomCard]



    cardsOut = cardsOut + 1
    print("cards out is currently: \(cardsOut)")
    cardSelect = cardSelect + 1

    UIView.animate(withDuration: 0.5, delay: 1.5, options: [], animations: {
        self.image.frame = CGRect(x: self.cardTwoLocation.x - (self.cardsOut * self.thirdWidth), y: self.cardTwoLocation.y, width: self.width, height: self.height)
        }, completion: nil)



    checkPlayerValue()

}

1 个答案:

答案 0 :(得分:0)

首先,确保将图像视图添加到视图控制器中。

其次,确保通过设置断点来调用动画。

第三,打印出位置并确保新的x和y有效,它们与前一个x和y不同。

以下是您的代码的示例副本,它可以正常使用

image = UIImageView(frame: CGRect(x: 100, y: 100, width: 100, height: 100))
image.backgroundColor = .red

self.view.addSubview(image)

UIView.animate(withDuration: 0.5, delay: 1.5, options: [], animations: {
    self.image.frame = CGRect(x: 200, y: 200, width: 100, height: 100)
}, completion: nil)

enter image description here