iOS CAShapeLayer and shadows with Core Animation - ios

I would like to draw a graph with CAShapeLayer and set a pretty shadow on a background for some nice visual effect. With shadows, animation of my graph (straight line to graph modeled using some data) really slows down!. I read about shadowPath property and decided to use it, but the problem is, despite the fact wether I close the CGMutable path or not, it seems like CoreAnimation closes it, and this shadow I get, instead of a line, is rather a polygon. Looks really ugly.
Help!

Related

Is it possible to animate a change in a UIView's lineDash stroke with Core Graphics/Animation?

I have a UIView subclass that does some drawing, and at one point calls CGContextSetLineDash to set the dash and gap information on the line stroke.
Is it possible to do this with an animation? If so, how? I find Core Graphics very confusing and I'm admittedly just getting started out with it.

Animate color of stroke's ends using CGPath

Quick diagrams! I'm trying to implement this:
I have this working almost 100% currently (though this is a slightly different stage of the animation):
Everything looks good minus the fade effects at the end of the stroke. Is that possible using a simple CGPath? I'm animating strokeStart and strokeEnd to get the current effect. I've tried using CAGradientLayer as a mask on the layer, but that adds a gradient over the entire layer, not just the ends. Overriding drawRect isn't possible since I'm doing this dynamically with animations.
Any thoughts about how to achieve this effect? I have no idea which direction to go.
Depending on how important opacity is and how complex the rest of the animation is, one option would be to make two blurred tail objects that follow the ends of the path as it is animating.
Roundabout solution, sorry I can't think of another versatile way!

iOS Strech Animation - Where should I start looking?

How can I achieve a stretch animation look?
Where do I need to start looking? CABasicAnimation does not seem to do the trick. Something like this: is the desired effect:
http://inspirationmobile.tumblr.com/post/112168531484/sidebar-animation-by-jacub-antalik-ramotion-com
There is a lot more than a simple animation in this view.
It is used UIKitDynamics, but the smart thing is that the final effect is composed by the single effects of small invisible UIViews inside that view.
The border is a CAShapeLayer made by a combination of bezier path that interpolates those single views.
Each drawing cicle, the CAShapeLayer path is refreshed based on the position of those views.
You can find more about this effect here.
For such a complicated shape animation look into CAShapeLayer and UIBezierPath. Look at this SO thread that might help you to get started at least.

Animating custom Bezier paths by looping drawRect

I have custom drawing code that uses bezier paths , gradients and strokes to perform my drawing. I want to run custom animations by looping drawRect and changing the values of properties on the bezier paths.
I have looked at using CAShapeLayer (UIView animation in drawrect) but that doesn't seem to cut it for me. My drawing code is quite complex, runs into a few hundred lines and all the drawing is done through bezier paths and gradients. Changing the drawings to a CAShapeLayer and then adding colors and gradients to it will be very time consuming!
I know that it is not recommended by Apple to explicitly call drawRect rather to use setNeedsDisplay to call draw rect (How to use DrawRect correctly). But the problem with doing that is i experience slight difference in the animation each time (very minute though). It may have something to do with the fact that setNeedsDisplay schedules drawRect to be called on the run loop but doesn't directly call it by itself.
I want to know what strategies i can use to use to loop drawRect and achieve synchronized perfectly timed animations each time. Is it possible to do this?
Both Animating Pie Slices Using a Custom CALayer and Animating Custom Layer Properties by Rob Napier are two good resources to learn how to make custom animations when you are doing completely custom drawing inside drawInContext:.
If you still feel that setting up an external mechanism to synchronize the drawing then I suggest that you look at CADisplayLink.

drawing shadow using core graphic and using CALayer

As far as I know we can use core graphic such as CGContextSetShadowWithColor to draw a shadow. However, we can also use CALayer to show the shadow as well.
Question :
what are the differences between 2 of them. Are there any rules to determine when we use core graphic to draw a or when we use CALayer to do the job
I would have to say that using CoreAnimation is always preferred over CoreGraphics, since it's more high level, and abstracts the low-level details of drawing the shadow. (It may also allow apple to optimize the shadow drawing without hurting your code syntax).
However, there are times where you are overriding drawRect: anyways, and you have very specific use for the shadow, not the whole view's layer. You might wanna use CoreGraphics shadows here.
One last note, CoreAnimation gradients are much faster when rendering, take my word for it. I used it on UITableViewCell, and the scroll performance significantly increased, as opposed to using CoreGraphics Gradients. That comes at a price, though. It's a bit worse-looking.

Resources