Combine a CALayer Position Animation with a Value Animation

//Combine a CALayer Position Animation with a Value Animation

Combine a CALayer Position Animation with a Value Animation

Combine a CALayer Position Animation with a value animation … ???

I came around this problem during a project where we should move a formatted text containing a number like, e.g. „It took x seconds to complete the task“. During the movement x should be incremented to following the timing function of the position animation.

I have to confess I had to think about it twice but shortly I thought CALayer can animation almost anything, so why not a custom variable.

So here is the basic idea.

I created a basic CALayer with our count instance variable which gives us the current count value during the position animation.

The implementation is as simple a telling our CounterLayer that we need an information whenever our count value changes. This is done with

+ (BOOL)needsDisplayForKey:(NSString *)key

method. This forces the layer to call its delegate

– (void)displayLayer:(CALayer *)layer

method

quite early in its update cycle to give the delegate the chance to update the contents property directly.

As we are only interested in the count’s current value, we grab it from the presentation layer for further use.

You can find the whole project on GitHub.

 

And here is the youtube video.

 

 

By |2018-06-06T20:31:46+00:00Samstag, Februar 1st, 2014|Development|0 Comments

About the Author:

Leave A Comment

For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.

I agree to these terms.