Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

johnny11

macrumors newbie
Original poster
Dec 29, 2010
2
0
Hi,

I have my custom UIView inside which I have a two dimensional array. This array contains pixels that I draw on my custom UIView with drawRect method.

Now I want to change this pixels (my 2-dim array) with 100 steps (or just with the result array). How do I make this effect animated? It is no problem to display previous state and then actual state, but I need animation between this states.

Thank You for any help.

Best regards, Wojtek
 
For now I did it in the following way:

Code:
- (void)calculate:(NSTimer *)timer {

int result = [myView calc];
if(result > 0)
{
    [NSTimer scheduledTimerWithTimeInterval:0.00001f
                                     target:self selector:@selector(calculate:)
                                   userInfo:nil
                                    repeats:NO];
}
[myView setNeedsDisplay];}
but it is not so good, because refreshing makes it very slow. If I refresh every 2-4 calculations my animation is not smooth.

MY drawing method:

Code:
- (void)drawRect:(CGRect)rect{
int i = 0, j = 0;

CGContextRef myContext = UIGraphicsGetCurrentContext();


// ****************** drawing ********************
for(i = 0; i < 768; i++)
{
    for(j = 0; j < 768; j++)
    {
         if(board[i][j] == 1)
         {
             CGContextSetRGBFillColor (myContext, 1, 0, 0, 1);
             CGContextFillRect (myContext, CGRectMake (i, j, 1, 1));
         }
        else
        {
            CGContextSetRGBFillColor (myContext, 0, 0, 1, 1);
            CGContextFillRect (myContext, CGRectMake (i, j, 1, 1));
        }
    }
}
}


I am looking for something as a replacement for drawing every single pixel every calculation.

Calc method from MyView is generating steps of my animation (changing "board" array).
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.