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?
These kinds of animations are called nested animations, because they are contained inside the movie clip symbols. Movie clip symbols have their own Timeline that is independent of the main Timeline. In this example, you'll give the alien his own independent movement, so he can wave as he flies across the Stage.
When you create a movie clip instance in a Animate document, the movie clip has its own timeline. Every movie clip symbol has its own timeline. The movie clip's timeline is nested inside the main timeline of the document. You can also nest a movie clip instance inside another movie clip symbol.
To be exact, whenever you want to animate the view, you actually call layoutIfNeeded on the superview of that view. Try this instead: UIView. animate(withDuration: 0.1, delay: 0.1, options: UIViewAnimationOptions.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With