I am trying to add a countdown to my app and I'm having problems animating this. The look I'm going for is something similar to the iPad countdown shown below, with the red bar increasing as the clock counts down.
Initially I created an image atlas with an individual image for each half second of the countdown but this seems to take a lot of memory to run and therefore crashes the app so I now have to find an alternative.
I've been looking at colorizing here https://developer.apple.com/library/prerelease/ios/documentation/GraphicsAnimation/Conceptual/SpriteKit_PG/Sprites/Sprites.html#//apple_ref/doc/uid/TP40013043-CH9 but can't see a way of colorizing a section of the sprite, it seems that the whole sprite would be changed.
Does anyone know if colorizing would be an option here, or is there a way of reduce the memory used by an image atlas?
Thanks
You can do it using CAShapeLayer and animating the stroke end as follow:
update Xcode 9 • Swift 4
define the time left
define a method to create de UIBezierPath
startAngle at -90˚ and endAngle 270
add your Label
at viewDidload set the endTime and add your CAShapeLayer to your view:
when updating the time
you can use this extension to convert the degrees to radians and display time
Sample project
Great piece of code and answer! Just thought I'd suggest the following. I was getting the time showing as 1:00 and then 0:60 which I think might be due to the "ceil" part of the code.
I changed it to the following (also wanting times less than 60 to show differently) and it seems to have removed the overlap of times.
For what it's worth ...