Random Animation - ios

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.

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.

Set corners of UIView (iOS)

I have the following problem: I'm scanning a QR Code with AVFoundation. This works quite well and I can also create a border around the code by adding a subview and set the frame attribute by subview.frame = qrCodeObject.bounds. This only has the problem that the border is only a rectangle and dismisses the perspective of the QR code.
I know that the qrCodeObject has a property corners which incorporates the top right, top left, bottom right and bottom left points of the QR code detected.
My question is now: how can I apply those corner points to the "border" view to make this border to have the same perspective as the QR code? Or in other words: how to "transform" the view according to the corner points?
Thanks a lot in advance!
UPDATE:
Here you can see the problem: the red box is a UIView, having it's frame property set to the QR codes bounds property. This misses perspective. I would like to transform the UIView (the red box) to following the corners property of the QR code, which includes the top right, top left, bottom right and bottom left points (CGPoint) of the QR code. It is important to apply this to a UIView, because I later want to apply it to an ImageView. Also a mask is not usable, as it just hides part of the view, but does not stretch or transform the content of the view.
I found a solution: AGGeometryKit did the trick: https://github.com/hfossli/AGGeometryKit/
Thanks everybody for helping!
You can't transform a CGRect that way, as far as I know. (At least I'm unaware of any framework that can do that kind of image processing.)
What you can do is to draw a polygon using the points of the qrCodeObject.
In drawRect of your UIView, change use CGContext and CGPath to draw the path you'd like.
You want your drawing UIView to be the same size as the one showing the QR code so that you don't have to translate the points onto a second coordinate space.
This answer has directions if you need more guidance on how to do that.
Ok, the problem you are facing is that a CGRect can only represent a rectangle that is not tilted or distorted. What you are dealing with is an image that has different kinds of perspective distortion.
I haven't tried to do this, but it sounds like AVFoundation gives you 4 CGPoint objects for a reason. You need to draw those 4 CGPoints using a UIBezierPath rather than trying to draw a CGRect. Simply create a bezier path that moves to the first point, then draws lines to each subsequent point, and finally, back to the first point. That will give you a quadrilateral that takes into account the distortion of your QR code.
CATransform3DRotate could be your friend, here.
https://guides.codepath.com/ios/Using-Perspective-Transforms might be a good starting point.

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.

iOS Circular Slider

I want to create a circular slider like below.
But i want two functionalities in addition.
1) I want to start the slider from any point,but in fig. it starts from 0.
2) I want to include multiple sliders in a single circular black plot.
I'm sharing the link of this project:
https://www.cocoacontrols.com/controls/circularsliderdemo
Can anyone help me to do these functionalities.
Thanks in advance.
Take a look at CAShapeLayer. You could create a path that is a full circle, and use the strokeStart and strokeEnd properties to only draw part of the circle. You could use core animation to animate between the beginning and the end.
There is an open source custom gesture recognizer on Github that is a one finger gesture recognizer. That would be a good start for detecting and responding to the twirl gesture that such a control would need. EDIT: It's called KTOneFingerRotationGestureRecognizer (link)
Those are some ideas to help get you started.
I have a project on github called iOS-CAAnimation-group-demo That includes a "clock wipe" animation. The clock wipe works by setting up a shape layer as the mask layer for an image view, installing a full-circle arc that's wide enough to completely fill a rectangular area, and then animate the strokeEnd property of the shape layer to reveal/hide the image view. The clock wipe is much more complex than what you need, but it would give you the seed of what you want. You'd use a shape layer with a much thinner line width, and you would use it as a content layer, not as a mask.

iPhone-Move UI Image view along a Bezier curve path

I want o move the UIImageView along a Bezier path, can anybody point me towards from where i can learn and achieve it.
An exact answer to that is probably very hard to do. But you may get close to what you want by using two CALayers, one a sublayer of the other. Put a x-translation animation on the one layer, and an y-translation animation on the other. Then experiment with custom animation timing functions for each of the translations.
See Animations Types and Timing Programming Guide

Resources