Pergunta

Let's say I have a timed UIAnimation, in the format of

[UIView animateWithDuration:DURATION_X
                 animations:^
 {
     [function that might contain a separate animation with DURATION_Y]
 }
                 completion:^(BOOL finished)
 {
     [function that might contain a separate animation with DURATION_Z]
 }];

If the nested animations also have durations inside them, how does that affect the outer animation? Are the inner animations executed with DURATION_Y and DURATION_Z, respectively, no matter what DURATION_X happens to be? Or is DURATION_Y animations scaled down or curtailed to end with respect to DURATION_X, assuming DURATION_X <= DURATION_Y?

Basically, what I'm asking in a nutshell is how we can control duration of inner animations safely, to ensure they execute with DURATION_Y (and not some shorter version) even when the outermost animation has a different and shorter DURATION_X?

Foi útil?

Solução

AFAIU, the inner animation takes control over the duration which is mentioned in the outer animation block. Whereas, function inside the completion block does not seem to wait until the main animation block finishes its animation task with the given time duration.

So, lets say DURATION_X is 5 seconds, DURATION_Y is 20 seconds and DURATION_Z is 10 seconds respectively. What happens is that the animation function inside the completion block gets triggered once the control completes (going to the function and do whatever) the main animation block (Having said the function inside the main animation block does have a different time duration). Hence, the function inside the completion block gets executed with the DURATION_Z and it does animate for the exact duration mentioned in DURATION_Z.

Along the side, the function inside the main animation block gets executed for the time duration specified in the DURATION_X ONLY. It ignores the time duration of DURATION_Y. A wacky code snippet here is:

-(void)doSomeAnim
{
    [UIView animateWithDuration:5.0
                     animations:^
     {
         [self animateOrangeBoy];
     }
                     completion:^(BOOL finished)
     {
         [self animateBlueBoy];
     }];

}

-(void)animateOrangeBoy
{
    [UIView animateWithDuration:20.0 animations:^{
        orangeView.frame = CGRectMake(orangeView.frame.origin.x, orangeView.frame.origin.y + 300, orangeView.frame.size.width, orangeView.frame.size.height);
    }];
}

-(void)animateBlueBoy
{
    [UIView animateWithDuration:10.0 animations:^{
        blueView.frame = CGRectMake(blueView.frame.origin.x, blueView.frame.origin.y + 300, blueView.frame.size.width, blueView.frame.size.height);
    }];
}

So, animateBlueBoy also starts along with the animateOrangeBoy but animateOrangeBoy lasts only 5 seconds but animateBlueBoy goes till 10 seconds.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top