在xcode中运行动画后,我需要将UIImage更改为不同的静态图像

时间:2016-01-11 20:41:21

标签: xcode swift animation static uiimage

因此,动画完成后似乎没有调用didRecieveMemoryWarning下的代码。我希望动画做的是当按下UI按钮时,它显示一系列UIImages被拖曳,然后经过6次重复计数后,它会停止在随机静态图像上,基于:

    @IBAction func playRoundTapped(sender: UIButton) {

    let firstRandomNumber = arc4random_uniform(2) + 1

    let firstCardString:String = String(format: "side%i", firstRandomNumber)

    self.firstDiceImageView.image = UIImage(named: firstCardString)

}

然而由于某种原因,每次动画完成时,它都会返回到“card_default”静态图像而不是“side%i”随机图像。

    override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    //Setting UIImages to Default
    self.firstDiceImageView.image = UIImage(named: "card_default")
    self.secondDiceImageView.image = UIImage(named: "card_default")
    self.thirdDiceImageView.image = UIImage(named: "card_default")
    self.forthDiceImageView.image = UIImage(named: "card_default")

    //Animation For Loop
    for i in 1...4
    {
        myImages.append(UIImage(named: "\(i)")!)

    }

    firstDiceImageView.animationImages = myImages
    firstDiceImageView.animationRepeatCount = 6
    firstDiceImageView.stopAnimating()

    secondDiceImageView.animationImages = myImages
    secondDiceImageView.animationRepeatCount = 6

    thirdDiceImageView.animationImages = myImages
    thirdDiceImageView.animationRepeatCount = 6

    forthDiceImageView.animationImages = myImages
    forthDiceImageView.animationRepeatCount = 6



}


override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

@IBAction func playRoundTapped(sender: UIButton) {

    let firstRandomNumber = arc4random_uniform(2) + 1

    let firstCardString:String = String(format: "side%i", firstRandomNumber)

    self.firstDiceImageView.image = UIImage(named: firstCardString)

}

0 个答案:

没有答案