iOS Strech Animation - Where should I start looking? - ios

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.

Related

How can I animate the drawing of a complex line shape in objective-c

So say I wanted to animate drawing this shape:
Animate it something like the disney logo which seems to "write" the letters.
Ideally, I'd also like to have control over how fast it was drawn (maybe just easing), how would I go about getting that done? Specifically imagine if that link had a line of varying widths.
Not too familiar with drawing things in objective-c so perhaps someone can help point me in the right direction in terms of strategy.
Create a CAShapeLayer and set that shape as its path. Use a CABasicAnimation or a CAKeyframeAnimation to animate its strokeEnd property.

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!

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.

Random Animation

I'd like to build a random animation of a imageview on iPad. What i manage to build so far is this:
The arrow represents my imageview. it moves to the bounds of its parent view an changes it direction. Actually this is not what i want. Id like to move the view randomly in it's parent view, in curves. And also adjust its heading, like in this figure:
I've no clue how to solve this and in particular how to generate a nice smooth path. Maybe someone has a hint for me.
Brad Larson answers a question that will give you some insight here: How do I translate parabolically?
Choosing random points is pretty easy and when you add them using a keyframe animation and a path, you get the smoothing you're looking for. You would just need to add the points to the path reference.
You add the path to the keyframe animation according to the link above and then add the animation to the UIImagView's layer with:
[[imageView layer] addAnimation:pathAnimation forKey:#"pathAnimation"];
Best regards.
Try out with Bezier curves with following
Drawing bezier curves with my finger in iOS?
and
CGPathReference
You would actually get quite far by just configuring the calculation mode of the key frame animation to be cubic
positionAniamation.calculationMode = kCAAnimationCubic; // or kCAAnimationCubicPaced
That will cause it to construct cubic splines between the points specified in the values array.

Shape animation in iOS

I have an UIView in which I draw many shapes. I just want to keep redrawing this view in order to make kind of an animation. I searched for animation options, but all animations looks like they only work with properties, like transform, alpha... I just want a timed animation option, and that do not block the screen, I mean, that allows the application to realize the screen was tapped. Is it possible?
It is totally possible and you have a few different ways that you can go about doing it. If you want a simple png sequence style animation you can just fill a UIImageView like this:
imageView.animationImages = myImages;
imageView.animationDuration = 3;
[imageView startAnimating];
or you can override the drawrect function in a custom UIView, set up an NSTimer to tick however frequently you want to change the animation and call setNeedsDisplay on the view to draw the next frame.
Assuming you have a bezier path that represents each shape, try looking at CAShapeLayer - this can be used to draw a path on the screen, and you can animate the position, fill colour and many other properties of it.
Have one CAShapeLayer per shape, and add them as sub layers to your main view's layer.
You need to add the QuartzCore framework to use it, but it is very straightforward and there are plenty of tutorials out there.

Resources