The serrated(shake) image will be shown when rotating the image if i use CATransform3DMakeRotation - iphone

I have a problem with the image rotated.
The serrated(shake) image will be shown when rotating the image if i use CATransform3DMakeRotation(M_PI, 0, 0, -1.0) to make a animation with layer.
The backgroundView is added into another animation view (same as the backgroundView, but the direction is reverse).
The code is:
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:#"transform"];
animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI , 0, 0, -1.0)];
animation.duration = 30;
animation.cumulative = YES;
animation.repeatCount = INT_MAX;
[backgroundView.layer addAnimation:animation forKey:#"animationOne"];
Thank you for your time.

The problem is fixed , to use the function can remove the serrate of image when rotating.
[self.layer setShouldRasterize:YES];

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.

How to rotate a view in 3d by 360 degree?

I am developing an app in which i am rotating a view by 360 degree but i am not able to rotate it 360 degree.
It is getting rotated by 180 degree and after getting rotated it is coming back to it's original position..
animation = [CABasicAnimation animationWithKeyPath:#"transform"];
transform = CATransform3DMakeRotation(3.14f, 1.0f, 1.0f, 1.0f);
value = [NSValue valueWithCATransform3D:transform];
[animation setToValue:value];
[animation setAutoreverses:YES];
[animation setDuration:0.9];
[[rotatBall layer] addAnimation:animation forKey:#"180"]; //rotatBall is a view
In other words,it is making back and forth rotation.
How to rotate it continuously....
Kindly help...
That's a little bit tricky but you can find it in the docs.
To rotate it continuously you first need to set the toValue then set the animation repeat count to HUGH_VALF (defined in math.h).
CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:#"transform.rotation.x"];
transform = CATransform3DMakeRotation(1.0f, 1.0f, 1.0f, 1.0f);
fromValue = [NSValue valueWithCATransform3D:transform];
transform = CATransform3DMakeRotation(M_PI*2, 1.0f, 1.0f, 1.0f);
toValue = [NSValue valueWithCATransform3D:transform];
animation.fromValue = fromValue;
animation.toValue = toValue;
animation.duration = 0.9f;
animation.repeatCount = HUGE_VALF; // HUGE_VALF is defined in math.h so import it
[rotatBall.layer addAnimation:animation forKey:#"rotation"];
Your animation is reversing after it finishes because you set autoreverses to YES. That's what autoreverses does.
As for why you're rotating by 180 degrees instead of 360... how many radians is 360 degrees?

move a CALayer (add animation)

well I have a CALayer layer and I would like to move it, with a CADisplaylink. Like :
layer.center=CGPointMake(layer.center.x + 10, layer.center.y + 10);
but I can't use center or position for the layer.Here is my problem, I want to make it move like it was a uiimageview.
To move layer try to use this method
-(void)moveLayer:(CALayer*)layer to:(CGPoint)point{
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:#"position"];
animation.fromValue = [layer valueForKey:#"position"];
animation.toValue = [NSValue valueWithCGPoint:point];
layer.position = point;
[layer addAnimation:animation forKey:#"position"];
}

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;

CALayer transformation - anchorPoint problem

I work on a card flip animation with CoreAnimation. The layer I want to animation is a UIView with UIImageViews as subviews. The animation approach:
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:#"transform"];
animation.duration=2.0f;
animation.repeatCount=1;
animation.fromValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(0.0, 0, 1, 0)];
animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 0, 1, 0)];
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards;
[layer addAnimation:animation forKey:#"flip"];
The problem is that the anchor point of the layer seems to wrong because it animates the view at the point x = 0. But the anchor point of the layer has the value (0.5, 0.5)
Any suggestions?