How to implement alternating colours animation on iOS - ios

I've designed a custom indicator View for my application which consists of a row of 10 circles. The indicator indicates the progress of a task and the closer the task is to finishing, the more circles are filled. I would like to add two very basic animations to this indicator and, because this is my first iOS application, I'm not sure what the best way to implement them is.
Animation 1: While the task progress information is being fetched from the server, I want each dot to change color (from black to blue) in succession.
Animation 2: Let's say I get that a task is 80% complete from the server, I want to change the color of the first 8 dots from black to green with a decreasing delay.
My question is, is it okay to implement these animations in drawRect: or is there a more standard way of implementing something like this.
Thanks!

I wouldn't use drawRect: at all for this UI. I would create the circles using a UIShapeLayer with a circle for its path, and do the animations with
animateKeyframesWithDuration:delay:options:animations:completion; this method allows you to add animations for the individual circles (using addKeyframeWithRelativeStartTime:relativeDuration:animations:) with whatever delay and relative duration you need between the keyframes.

Related

How do I create a segmented circular progress bar in Swift?

I wanted to create a progress bar as shown in the image:
I used the code mentioned in this blog
but I am unable to add separators and reduce the space between them.
I have managed to do like this through storyboard:
How can I change the code or is there any easier way to create?
You didn't specify what sort of animation you want on your progress indicator, but certainly achieving the drawing you've shown in your first screenshot shouldn't be any problem; I was able to throw this together in a couple of minutes:
Each thing in that drawing (other than the face) is a CAShapeLayer: the dark background circle a shape layer, the animated green circle in front of it is a shape layer, and each of the eight little lines that indicate the segments is a shape layer. So I have ten shape layers in total. They are added in that order, so that the little lines appear in front of everything else.
If the goal is to "fill" each segment in discrete steps, rather than a smooth animation through all values, that's a trivial modification of what I've already described.

Animation Corresponding to UITimer

I am coding a game in Swift where the player has to make a move within a second, or else time runs out and he/she loses. How can I make an animation that runs every second, resembling the one in the top of Snapchat stories, where it is a filled in circle that slowly "wipes" away in a circular motion like a windshield wiper? Is it just a second-long GIF that I loop every second? Is there a way to do this with native UIKit graphics?
I think what you are looking for is a "clock wipe" animation. You can do that by adding a mask layer to your image and animating it using Core Animation.
I wrote a SO post on this very subject:
How do you achieve a "clock wipe"/ radial wipe effect in iOS?

Watchkit animation implementations: clock face, animated charts, circular progress bar

I've seen some very basic demos of potential watchkit apps, and some appear to implement animations. Examples might be:
A clock face with a moving second hand or even minute hand.
A bar chart with bars that animate in, or who shape changes with new real-time data.
A circular progress bar who's bar animates from zero to the current value.
The only way I've seen so far to do animations is by a sequence of images over a duration:
[imageView startAnimatingWithImagesInRange:NSMakeRange(0, 60) duration:1.0 repeatCount:0];
How would these previous animation examples generally be implemented? I can't imagine they are all done with image sequences. I don't think one can even layer images, and coordinating placement would be a nightmare.
They are all done with sequences of images. Here is some code for how I animate movement on a map. Is it possible to position views on top of each other
Edit
You may also find these frameworks helpful.
https://github.com/frosty/Flipbook
https://github.com/radianttap/WatchRingGenerator
2nd Edit
Here is another great article on adding animation into your Watch App. http://david-smith.org/blog/2015/03/04/ailw-adding-bits-of-liveliness/

masking a background colour over the transparent region of a UIImage in objective C

Im a little bit lost on how to go about this, im really looking for the theory behind it im not 100% sure if the title is correct or not.
Im currently working on a iOS app and im a little stuck with the progress indicator thats been designed ive attached a image of it below
as you can see when the user progresses through the stages of the challenge the background of this image fills up with white so if they are in stage 1 of a 5 stage challenge its filled 20% stage 2 40% etc.
the issue I have is im not 100% sure how to go about this, if I was doing this in HTML i would create the image with the green background and leave the area for the rabbit and shape transparent and then create a div behind it that would change its height.
should I be applying the same principle to iOS development or should I be building it in a more programatic and efficient way.
thanks all for your help
The solution you are talking about sounds fine. Many programmatic solutions would involve masking and would probably be less performant (masking is actually quite expensive), other programatic solutions involve stroking different vector paths but that would get complicated if you want to cut them all of a the same line.
So, translating your idea into views. Create a container UIView with a light green background, and add to it a white UIView and an UIImageView (in that order to get the image on top). The image view would have the green image with transparency set as its image. The white view would start of being positioned below the light green view (have a frame with a higher y value) and as the stages progress you simply shift the white view upward by modifying it's center or frame properties. (note that y increases downwards).
This may be a childish way
Make an UIImageView and add that in your view where you place your rabbit view.
Make the width and x axis value as same of your rabbit view and change the height and y-axis value as the stages completes.
Add the rabbit view above your imageview.
In this way you can have not only color of your progress you can even assign a image in future to show the progress of the different changes.
-(void)completedStage:(int)stage
{
CGRect frame=rabbitimage.frame;
bgimageview.frame= CGRectMake(rect.orgin.x,rect.frame.orgin.y+rect.frame.size.height-stage*0.2,rect.frame.size.width,rect.frame.size.height-0*2)
}
Hope this helps !!!

iOs draw an intereactive map

I need to draw an interactive map for an iOs application. For example it can be the map of the US showing the states. It will need to show all the states in different colors ( I'll get this from a delegate colorForStateNo: ) It will need to allow the user to select a state by touching it, when the color will change, and a "stick out" effect should be shown, maybe even a symbol animated to appear over the selected state. Also the color of some states will need to change depending on external events. This color change will mean an animation like a circle starting in the middle of the state and progressing towards the edges changing the color from the current one to the one inside the circle.
Can this be done ,easily in core-graphics? Or is it only possible with Open GL ES? What is the easiest way to do this? I have worked with core graphics and it doesn't seem to handle animation very well, I just redraw the entire screen when something needed to move... Also how could I use an external image to draw the map? Setting up a lot of drawLineToPoint seems like , a lot of work to draw only one state let alone the whole map ...
You could create the map using vector graphics and then have that converted to OpenGL calls.
Displaying SVG in OpenGL without intermediate raster
EDIT: The link applies to C++, but you may be able to find a similar solution.

Resources