簡體   English   中英

無法為UIImageview設置動畫

[英]Cannot animate UIImageview

我的問題是,當我按下運行DealToPlayer function()的按鈕時,一切都好像已發行了一張牌,更新了已發行牌的總值,但沒有顯示正在發行或放置的牌的任何動畫。 為什么會這樣呢? 我根本沒有為該場景使用自動布局。

  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()

}

首先,確保將圖像視圖添加到視圖控制器。

其次,確保通過設置斷點來調用動畫。

第三,打印出位置並確保新的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)

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM