views:

298

answers:

3

Hi, all! I'm developing a game in which I'm reducing the frame size of an imageView. When I'm introducing a condition using while loop, I'm not able to see the image reducing its size gradually, since it immediately jumps to the final result. So, I want to introduce a delay after every instruction so that I can see the effect of its size reduction little by little. I can't use timer since it needs me to specify a function to be executed after that time interval.

while(ravanImage1.frame.origin.y>=end.y)
{
ravanImage1.frame=CGRectMake(150,((ravanImage1.frame.origin.y)-5),q,z);

if(ravanImage1.center.y>=300&&ravanImage1.center.y<=370)
{
    q=60;
    z=60;
    ravanImage1.frame=CGRectMake(150,((ravanImage1.frame.origin.y)-5),q,z);
}   

if(ravanImage1.center.y>=230&&ravanImage1.center.y<=299)
{
    q=40;
    z=40;
    ravanImage1.frame=CGRectMake(150,((ravanImage1.frame.origin.y)-5),q,z);
}

if(ravanImage1.center.y>=150&&ravanImage1.center.y<=229)
{       
    q=20;
    z=20;
    ravanImage1.frame=CGRectMake(150,((ravanImage1.frame.origin.y)-5),q,z);
}
}

I want to introduce delay after every frame change.

Can anybody please help me?

A: 

Hi

So use the timer and give it a function which will take up the right amount of time to execute but have no impact on your display ? Maybe run a long loop of meaningless calculations at the right place in your program ?

Regards

Mark

High Performance Mark
Thanx, Mark! I'll try this one..
neha
A: 

If you just need to pause the change during development, use the debugger's breakpoints.

For release, you should use an animation block to make the changes. Create a separate block for each possible change and then set the animation duration to what you'd like.

As a general rule, you never change the frame of a view directly anymore unless you wish it to be instantaneous. Animations exist precisely for this purpose i.e. to create an effect that communicates a change in view state to the user. They're not just eye candy.

If for some reason, you don't want to use animations, you could move each size change into it's own method and then call each method with a timer. You could call the first method, which would set a timer to call the second, which would set a timer to call the third and so on.

TechZen
I really dont want to use animations as they create problem in my app. The latter method sounds good. I'll try...
neha
You're to have a lot of extra work then. The API is based around animations.
TechZen
+2  A: 

How about using

[NSThread sleepForTimeInterval:]

inbetween every instruction?

Michael
No, I cant use this as entire execution of my program is going on on single thread. What I want to halt is just a part of it.
neha