Reputation: 1393
I have a global variable p. I have a function that draws (or redraws) my complex UIView objects depending on the value of this global variable. When I increase p my uiview objects needs to be redrawed. I need this be done using animation.
double pInitialValue=0.5;
double pNewValue=1.0;
//somewhere before animation we must call [self redraw] to draw our view with p=pInitialValue;
//then, when we call animate function.
//we change p to pNewValue
//and every step must be redrawed using [self redraw]
p=pNewValue; //using animation p must slowly grow from pInitialValue to pNewValue
[self redraw]; //and ofcourse user must see every step of animation so we need to call redraw function
for example I need an animation with duration 4. That means that during this 4 seconds my p must grow from pInitialValue to pNewValue and in every step my redraw function must be called
Help me, please. How can it be done?
Upvotes: 0
Views: 459
Reputation: 7663
You can use a timer to increase your p
value. Do that like this: have an instance variable in your class defined like
NSTimer *timer;
After that just before you want your animation to happen do:
CGFloat timerInterval = 1 / 30; // This means 30 frames per second. Change this as you want.
timer = [NSTimer scheduledTimerWithTimeInterval:timerInterval target:self selector:@selector(increaseP) userInfo:nil repeats:YES];
Than have a method called increaseP
like this:
- (void)increaseP
{
if (p < maxPValue) {
// Increase p here and redraw your things
}
else {
[timer invalidate];
}
}
Let me know if you have any question and if this works for you.
Upvotes: 1