0

Nested animation

In short the nested animation allows to run 2 independent animations simultaneously. But what to do if I have a complex code which consists of both animated and non-animated code? I mean the following situation:

[UIView animateWithDuration:... animations:^{ ...//code1 - with animation ...//code2 - also contains code which shouldn't be animated }]; 

Code2 looks like the calling of the following method:

- (void)someMethod { ...//code3 - without animation [self someMethod2Animated:NO completion:^{ [self someMethod2Animated:YES completion:^{ NSLog(...); }]; }]; } 

Where someMethod2 executes the same code but maybe inside the animatedWithDuration:animations:completion: depending on the given BOOL variable.

If I run this code then I see that all the code parts are animated. I tried to set the durations of the code2 to zero but it has no effect (the code is still animated).

Could you suggest how to solve this issue without of rewriting all the code? I heared about some solutions like ReactiveCocoa but it seems they are suitable for network/separate asynchronous requests only.

Edited

PromiseKit 2.0 allows to convert enclosed animation blocks to a sequence of blocks but it doesn't support iOS 7 I need.

2 Answers 2

0

UIView animateWithDuration is great for very simple (non-interactive) animations. For what you are doing, you should dive into CAAnimation. UIView animateWithDuration will animate any view changes which occur anywhere within the block.

You are basically looking to conditionally chain your animations. Here's a good answer about chaining animations. How to chain different CAAnimation in an iOS application

Sign up to request clarification or add additional context in comments.

4 Comments

Is true for beginAnimations:context: + `commitAnimations too?
Anyways in the pure state this solution requires to rewrite all the code and to increase the amount of my code at least thrice: 1)original code; 2)every animated action should be written separately with separate CAAnimation object (even if a couple of actions could be simply written in one animateWithDuration block); 3)requires additional objects CAAnimation + as you wrote some troubles for creating a sequence of animations. Maybe you could avice a wrapper over it?
Yes, beginAnimations, commitAnimations will give you the same challenges as UIView animateWithDuration. If you follow the direction in the link you only create the CABasicAnimation objects for the actions you want to animate. You execute the other UI changes normally. I agree this will be more code, but you are looking to do something more expressive than what animateWithDuration will provide.
Thanks for answer but you are mistaken for animateWithDuration because RZViewActions is fully built on it but provides a simply way to create serial and parallel animations.
0

The best solution I found out is RZViewActions. Advantages for my case:

  • operate with animations as with objects without nested blocks;

  • serial and parallel animations are "sequences" and "groups" which are objects too created from simple arrays of animations;

  • just take its demo, remove [self.spinner startAnimating];, run and click the screen multiple times. A lot of animations are performed simultaneously even without any special code (in case of animateWithDuration: the next animation would kill the previous unfinished one).

The second solution could be PromiseKit 2.0. It may be run under iOS 7 but it needs some magic to be added to the project.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.