Reputation: 103
The program I'm writing has a view with several tiles on it that are scrambled properly when the following code is executed:
[self scrambleBoard];
[self.view setNeedsDisplay];
where scrambleBoard is a method I have that mixes up the tiles randomly. The above code works correctly and shows the final scrambled position of the tiles.
The problem I have is that I want to give the program the appearance of the tiles actually scrambling, sort of like animation, but not really so, it would just show 8 consecutive different scrambled views. So I incorporated the above code into the following loop:
for (int i = 0; i < 8; i++)
{
[self scrambleBoard];
[self.view setNeedsDisplay];
usleep(250000);
}
The problem is that instead of showing 8 different scrambled views in succession, I only get the final scrambled view. Any help would be appreciated - thanks in advance Gil
Upvotes: 0
Views: 35
Reputation: 38728
My guess is that you are simply blocking the thread as a sleep is almost always the wrong thing to use on the main thread.
I believe the final view is only really calculated at the end of the runloop which will essentially just give you the result of the last jumbling.
Upvotes: 1