Smoother Slow Rotating UIImage - iphone

I'm trying to make an iPhone/iPad app, and I am currently trying to have an image spin slowly 360 degrees. But when I increase the animation duration, the picture rotates 1/4 of the way and then resets back to the beginning of the animation.
Can anyone tell me what is wrong with this?
What I have so far:
CABasicAnimation *fullRotation = [CABasicAnimation animationWithKeyPath:#"transform.rotation"];
[fullRotation setFromValue:[NSNumber numberWithFloat:0]];
[fullRotation setToValue:[NSNumber numberWithFloat:((2*M_PI))]];
fullRotation.speed = .5f;
fullRotation.duration = 5.5;
fullRotation.repeatCount = 1;
fullRotation.repeatCount = HUGE_VALF;
[[cosmic layer] addAnimation:fullRotation forKey:#"transform.rotation"];

Just delete this one line from your code:
fullRotation.speed = .5f;
and then adjust duration you want.

Related

Moving an image using Core Animation

Any idea why the small image that I move across the screen gets blurry?
While being in motion, the small details in the image become unclear and I think that it is a problem.
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:#"position"];
anim.fromValue = [NSValue valueWithCGPoint:CGPointMake(px2.x, px2.y)];
anim.toValue = [NSValue valueWithCGPoint:CGPointMake(P3x, P3y)];
anim.duration = 1.5f;
anim.repeatCount =1;
anim.removedOnCompletion = YES;
anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
[LA addAnimation:anim forKey:#"position"];
Eventually this was identified as LCD panel lag.

Motion blur during CABasicAnimation

I have this simple animation that moves an image from one point to another:
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:#"position"];
anim.fromValue = [NSValue valueWithCGPoint:CGPointMake(px2.x, px2.y)];
anim.toValue = [NSValue valueWithCGPoint:CGPointMake(P3x, P3y)];
anim.duration = 1.5f;
anim.repeatCount =1;
anim.removedOnCompletion = YES;
anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
[LA addAnimation:anim forKey:#"positionTest"];
The problem is that the image becomes blurry while in motion, the motion is not very fast.
Is there a way to reduce this motion blur?
If you take a screenshot during the animation is it definitely blurred? Also is the blurring a pixellated blur or is it more like a soft gaussian blur?
Try setting view.layer.shouldRasterize = yes and layer.rasterizationScale = UIScreen.mainScreen.scale;

(iphone) how to animate several images with speed variations between images?

this must have been asked and answered but couldn't find an answer.
What I'd like to do is basically animating images like
image1 0.1sec
image2 0.3sec
image3 0.2sec
image4 0.5sec
I have looked at CAKeyFrameAnimation but can't be sure if that's what I needed.
(have almost none image/animation programming background)
Thank you
CAKeyFrameAnimation is for one object to animate differently in different phases of one animation. For example, your object first moves to a point, then continues the same animation to another point, then one another.
You can use CABasicAnimation with different duration values for each image you want to animate.
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:#"position.x"];
anim.delegate = self;
anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
anim.toValue = [NSNumber numberWithFloat:50.0];
anim.duration = 0.1;
[image1 addAnimation:anim forKey:#"position.x"];
anim.duration = 0.3;
[image2 addAnimation:anim forKey:#"position.x"];
anim.duration = 0.2;
[image3 addAnimation:anim forKey:#"position.x"];
anim.duration = 0.5;
[image4 addAnimation:anim forKey:#"position.x"];

How to get layer point?

I am using this code to rotate a needle (like in a speedometer):
CALayer* layer = someView.layer;
CABasicAnimation* animation;
animation = [CABasicAnimation animationWithKeyPath:#"transform.rotation.z"];
animation.fromValue = [NSNumber numberWithFloat:0.0 * M_PI];
animation.toValue = [NSNumber numberWithFloat:1.0 * M_PI];
animation.duration = 1.0;
animation.cumulative = YES;
animation.repeatCount = 1;
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards;
[layer addAnimation:rotationAnimation forKey:#"transform.rotation.z"];
Now my question is that during the animation i press one button at that time needle is back to move on particular point. So i must have to get last point of layer when i touch button.
How to get last point of layer?
Your question is very hard to understand, but it seems like you are asking how to determine the state of a progressing animation at the moment a user presses a button. To do this, you can get a CALayer's presentationLayer, and query that for the current value of the property being animated.
The answers to this question show you how to determine the angle of your rotated presentationLayer. You probably want to ignore my needlessly complex answer there.

Moving Image 360 Degree

How can we Move an Image 360 Degree from the starting point to the ending point?
Moving Image 360 Degree?
You can rotate a view, by some number of radians, regardless of whether it is less than a full rotation or many multiples of a full rotation, without having to split the rotation into pieces. As an example, the following code will spin a view, once per second, for a specified number of seconds. You can easily modify it to spin a view by a certain number of rotations, or by some number of radians.
- (void) runSpinAnimationWithDuration:(CGFloat) duration;
{
CABasicAnimation* rotationAnimation;
rotationAnimation = [CABasicAnimation animationWithKeyPath:#"transform.rotation.z"];
rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 /* full rotation*/ * rotations * duration ];
rotationAnimation.duration = duration;
rotationAnimation.cumulative = YES;
rotationAnimation.repeatCount = 1.0;
rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
[myView.layer addAnimation:rotationAnimation forKey:#"rotationAnimation"];
}
A 360 degree rotation in any axis leaves the view unchanged. So don't touch the image, and you're good to go!
You could use an animation function (CAValueFunction) for this too:
CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:#"transform"];
rotationAnimation.duration = duration;
rotationAnimation.fromValue = [NSNumber numberWithFloat:0.0];
rotationAnimation.toValue = [NSNumber numberWithFloat:M_PI * 2.0];
rotationAnimation.valueFunction = [CAValueFunction functionWithName:kCAValueFunctionRotateZ];
rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
[myView.layer addAnimation:rotationAnimation forKey:nil];