UPDATED PROBLEM DESCRIPTION - How to create a "spinning" effect?


Perhaps I was not clear in my earlier description, so I have attempted to simplify it.

I have a single image in my view and a button (called ROLL).
The button when pressed does the following:
calls a method that randomly picks a number between 1 and 6
it then updates my image, based on my random number, with the appropriate graphic (dice image)
This is all that is involved.

What I would like to do is to create a “spinning” effect of my image.

Currently I try to do this my creating a loop (say 100 times) in the method that randomly selects a new image.
This DOES NOT work.
What happens, is only the last iteration (100th) updates the image. There is no “spinning” effect.

I did notice that if I repeatedly press the ROLL button the image updates and creates the “spinning” effect I want.
My conclusion is that some sort of display update must occur after each press of the ROLL button. Whatever update is happening there is what I need to put into my loop.

Does anyone know what code I need to cause this display update, and thereby create my “spinning” effect???

Thanks - Ed

It would help if we could see what code you are using.

What do you mean that only the last iteration updates the image? Do you mean you have 100 images for every face of the dice that you use to create the spinning effect?

What could be happening is that the loop is so fast that you only see the last image. Try delaying the loop a bit.

Below is the relevant code. Basically a button is pushed and the dice are “rolled” In the method called by the button is where I am looping. I have pushed the loop up as high as a million so I don’t think the problem is that it is going too fast that I can’t see it. The image just freezes until until it reaches the final iteration.
Please let me know if you need more relevant info. - Thanks

@IBAction func rollButton(sender: UIButton)
for _ in 0…1000 { rollTheDice() }

func rollTheDice()
var randomDiceValue = 0

    //---   loop thru and get new value for each of our 6 dice   ---//
    for currentDice in 0…5
        //---   only process if die is not held   ---//
        if (self.dice[currentDice].diceHoldStatus == false)
            //---   generate a random number between 1 & 6 for our die   ---//
            randomDiceValue  = Int(arc4random_uniform(6)) + 1
			//---   get name of new dice image   ---//                    
            self.diceNameString = self.diceNameArray[randomDiceValue]

			//---   display the new dice image value   ---//
            dice[currentDice].diceTopImageView.image = UIImage(named: self.diceNameString)
        }  // currentDice in 1..<global.MAX_DICE_PER_ROW
    }  // end function -->  rollTheDice()