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

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/

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.

How can I animate in the entrance of a CAEmitterCell?

Currently my particles appear on screen abruptly in their full shape and form. What I want is for the cells to either start at 0.0 opacity and animate up to full opacity, or start at 0.0 scale and animate up to 1.0 scale. I can't find anything online on how to do this.
You can animate the various properties of a CAEmitterCell, there is a good example at animating the CAEmitterCell Color property that should give you a good idea of what you should do to get the effect you want.
There are lots of great resources on CAEmitters, one good one is Tutorial: Particle Systems in Core Animation with CAEmitterLayer and another is Apple's Fireworks Sample Code

How can I reproduce a "box" transition animation in iOS?

I want to build an animated transition between two view controllers in iOS, resembling the "Box" transition in PowerPoint or the "Reflection" transition in Keynote.
You can see it here, at 2:10:
http://youtu.be/1fLQg5hFQQg?t=2m10s
What's the best way to do this?
Thanks!
That would be a complex animation to recreate. You'd need to use a CAAnimationGroup that grouped several different animations running at once. You'd want to animate a rotation around the y axis with the center of rotation lifted off the screen, on both the view controller that is animating away and the view that your are animating into place.
You would have to tweak the transform to make it draw with perspective (you add a small value to the .m34 record in the transform). That's because CA animations are orthographic by default (they don't show perspective.)
The reflections could be created using a special subclass of CALayer that lets you create duplicates of a layer. I'm blanking on the name of that layer subclass at the moment. You'd set up 1 duplicate with a scale of -1 on the y axis to flip it upside down, and a darkening effect. I've never done it myself, but I've seen several examples in books and online.

How to animate a pulsating blue dot with Core Animation?

I am a Core Animation newbie and I want to animate a pulsating blue dot very similar to what the Maps application does with the GPS position.
This is not in a map, and this doesn't use Map Kit. It's inside one of my own views (a UIImageView subclass actually), itself inside a UIScrollView.
I am just starting and I am hopeful for suggestions, best practices, perhaps sample code, to speed up my development.
Note a peculiar twist: the look (size) of the pulsating blue dot should preferably not depend on the zoom factor of the host view in its scroll view. I believe Map Kit behaves similarly.
The intent is to attract the user's attention to a specific tiny portion of a crowded image.
Thanks for any suggestion.
You could use two pre-generated images (one with "low light" and one with "high") and animate the transition between the two images. You'd want to use an ease-in curve similar to the map dot (speeds up as it gets brighter) and have it auto-reverse and repeat.
Alternatively, you could use a view with a blue-tinted shadow whose blur radius property is animated between zero and several pixels. With this latter approach, your custom-drawn dot could easily take the scale factor into account when drawing.

Custom UIview free rotation too slow

Programming for iOS, I have a composite custom view consisting of many UIViews. Some UIViews in this composites are responsible for drawing shadow and others for some custom shading. The shadow and shading need to be redrawn upon rotation recognized by UIRotationGestureRecognizer. However the speed of the rotation is far from satisfactory. When I commented out setNeedDisplay, the rotational speed is fine. However, if I do call setNeedDisplay, even when I commented out everything in all drawRects for the shadow and shading views, the rotation still lags significantly.
Are there any recommendations to speed things up?
I can think of one possible solution: make sure the system calls drawRect less often while in rotation. But I do not know how to do this, nor do I know if this is the best solution. Any suggestion appreciated. Thanks.
Calling setNeedsDisplay: too often, especially every frame will always be slow. setNeedsDisplay runs on the CPU, not the GPU. Don't redraw views during rotation and zooming. Wait until the end of the animation, then call setNeedsDisplay: to "render" the final position.
Take a look at how various UIKit views handle large animations:
While MapKit zooms in, the map image scales and looks blurry. Once the zoom gesture stops it renders a new image at that scale. (In this case the image is downloaded from the internet, but it still illustrates the concept.)
ZoomingPDF Sample code (see apple developer docs) shows how zooming on PDFs doesn't render in realtime, but after the zooming finishes.
Hope this helps.

Resources