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
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.
Privacy & Cookies Policy
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.