Moving an image using Core Animation - iphone

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.

Related

Flipping two UIView using CATransform3D

I have created Visiting Card which has Front view & back View. When i tap on the front view it should flip the UIView & show the back side of the View.
Here is Code which I am trying:
CATransform3D transform = CATransform3DMakeRotation(M_PI, 0, 1, 0);
transform.m34 = 1.0/700.0;
CABasicAnimation *rotation = [CABasicAnimation animationWithKeyPath:#"transform"];
rotation.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
rotation.toValue = [NSValue valueWithCATransform3D:transform];
rotation.duration = DURATION;
CABasicAnimation *translation = [CABasicAnimation animationWithKeyPath:#"position"];
translation.fromValue = [NSValue valueWithCGPoint:CGPointMake(self.imageview.center.x,[[self.imageview superview] center].y-45)];
translation.toValue = [NSValue valueWithCGPoint:CGPointMake(_frame.origin.x+_frame.size.width/2,
_frame.origin.y+_frame.size.height/2)];
translation.duration = DURATION;
CABasicAnimation *translation = [CABasicAnimation animationWithKeyPath:#"position"];
translation.fromValue = [NSValue valueWithCGPoint:CGPointMake(self.imageview.center.x,[[self.imageview superview] center].y-45)];
translation.toValue = [NSValue valueWithCGPoint:CGPointMake(_frame.origin.x+_frame.size.width/2,
_frame.origin.y+_frame.size.height/2)];
translation.duration = DURATION;
CAAnimationGroup *group = [CAAnimationGroup animation];
group.animations = #[ translation, rotation ];
group.duration = DURATION;
group.delegate = self;
group.fillMode = kCAFillModeForwards;
group.removedOnCompletion = NO;
[layer addAnimation:group forKey:nil];
Above code works perfectly for single view. How to combine the 2nd view to get flipping from front & back effect.
Using Core Animation
You can add both front and back to a container view. The back view will have a 180 degree rotation around Y and the front will be just normal. Both layers will be single sided (by setting layer.doubleSided = NO;.
Then when you apply the rotation you would animate the rotation of the container view so that both front and back animate at the same time.
UIView transitions
Or you could just use the built in flip animation
transitionFromView:toView:duration:options:completion:
and pass either UIViewAnimationOptionTransitionFlipFromLeft or UIViewAnimationOptionTransitionFlipFromRight for the option.

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;

Stop CABasicAnimation from being removed after completion

Hey, I have this code snippet (duration is .5, amount is 1.5)
CABasicAnimation *grow = [CABasicAnimation animationWithKeyPath:#"transform"];
grow.duration = duration;
grow.repeatCount = 0;
grow.removedOnCompletion = NO;
grow.autoreverses = NO;
grow.fromValue = [NSValue valueWithCATransform3D:CATransform3DScale(self.layer.transform, 1.0, 1.0, 1.0)];
grow.toValue = [NSValue valueWithCATransform3D:CATransform3DScale(self.layer.transform, amount, amount, amount)];
grow.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[self.layer addAnimation:grow forKey:#"grow"];
However when this is played, the UIView grows properly, but then snaps back to its starting value. I thought the "removedOnCompletion" was supposed to prevent this?
Looks like I also needed to specify:
grow.fillMode = kCAFillModeForwards;
Go figure. Works now :)

(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"];

Load an animation image while running a function in Iphone SDK

I want to load an animation image while running a function (like: loading....).
How can I do in iphone SDK?
Use CoreAmination.
self.layer.transform = CATransform3DRotate(self.layer.transform, M_PI, 0.f, 0.f, 1.f);
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:#"transform"];
animation.toValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
animation.autoreverses = NO;
animation.duration = 1.00;
//animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
animation.repeatCount = HUGE_VALF;
[self.layer addAnimation:animation forKey:#"spinner"];