CGAffineTransform block others animation - ios

i have two images(iphoneImage , ipadImage) and i want to move ipadImage and rotate iphoneImage but when i use CGAffineTransform on iphoneImage it blocks ipadImage Move ??
so any suggestions
CGRect tempRect=CGRectMake(-351, self.ipadImage.frame.origin.y,
self.ipadImage.frame.size.width,
self.ipadImage.frame.size.height);
CGAffineTransform transform=_iphoneImage.transform;
transform = CGAffineTransformRotate(transform, M_PI * 90 / 180.0);
[UIView animateWithDuration:2
animations:^{
_ipadImage.frame=tempRect;
_iphoneImage.transform=transform;
}];

Related

Scale/Animate One Side of UIView to Be Smaller? - CGAffineTransformMakeScale

I would like to animate a UIView so its right side becomes smaller and then back again. This animation will trigger when a UIButton in this UIView is tapped. Here is a quick mockup of what I would like - the UIView will go from state 1 > state 2 > state 1:
It looks like it is being pushed on one side.
Here is the code I have for another action - this makes the UIView smaller and larger again as if it is being pushed on the centre, rather than the side.
self.myView.transform = CGAffineTransformMakeScale(0.95,0.95);
self.myView.alpha = 1.f;
[UIView beginAnimations:#"button" context:nil];
[UIView setAnimationDuration:0.5];
self.myView.transform = CGAffineTransformMakeScale(1,1);
self.myView.alpha = 1.0f;
[UIView commitAnimations];
How do I apply this same effect but only to the right side? Any help would be much appreciated, thanks!
According to this question u need t make Perspective Transform for example, i modified a bit from that question i linked
CATransform3D perspectiveTransform = CATransform3DIdentity;
perspectiveTransform.m34 = 1.0 / -500;
perspectiveTransform = CATransform3DRotate(perspectiveTransform, 40.0f * M_PI / 180.0f, 0.0f, 1.0f, 0.0f);
[UIView animateWithDuration:0.4 animations:^{
self.myView.layer.transform = perspectiveTransform;
}];
EDIT 2 Brings back to original
- (void)startAnimation:(id)sender
{
CATransform3D perspectiveTransform = CATransform3DIdentity;
perspectiveTransform.m34 = 1.0 / -500;
perspectiveTransform = CATransform3DRotate(perspectiveTransform, 40.0f * M_PI / 180.0f, 0.0f, 1.0f, 0.0f);
[UIView animateWithDuration:1.4 animations:^{
self.myView.layer.transform = perspectiveTransform;
}completion:^(BOOL finished) {
CATransform3D originalPerspectiveTransform = CATransform3DIdentity;
[UIView animateWithDuration:0.9 animations:^{
self.myView.layer.transform = originalPerspectiveTransform;
}];
}];
}

How to rotate the image from original and back to it?

I have try to rotate the image by using CGAffineTransformMakeRotation and CGAffineTransformRotate. I want to rotate the image from it's original and clockwise to the original again(like degree 0 to 360). I need to rotate image like a CD on the player. I did something like this:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.1];
CGAffineTransform transform = CGAffineTransformMakeRotation(1.0);
transform = CGAffineTransformRotate(transform, -180);
ImageView.transform = transform;
[UIView commitAnimations];
it just spin to the degree 180, and if I change it to -300 it will rotate counterclockwise (that not what I need).
the angle of rotation is given better by atan2() suppose A and B are two points on the centerline to which your image is to be rotated then the angle of rotation is
0-atan2((b.x - a.x) ,(b.y -a.y))
Hope this helps
Try this:
-(void)startAnimationWithRevolutions:(float)revPerSecond forTime:(float)time
{
spinWheel.userInteractionEnabled = FALSE;
float totalRevolutions = revPerSecond * time;
[CATransaction begin];
[CATransaction setValue:[NSNumber numberWithFloat:time] forKey:kCATransactionAnimationDuration];
CABasicAnimation* spinAnimation = [CABasicAnimation
animationWithKeyPath:#"transform.rotation"];
CGAffineTransform transform = spinWheel.transform;
float fromAngle = atan2(transform.b, transform.a);
float toAngle = fromAngle + (totalRevolutions*4*M_PI);
spinAnimation.fromValue = [NSNumber numberWithFloat:fromAngle];
spinAnimation.toValue = [NSNumber numberWithFloat:toAngle];
spinAnimation.repeatCount = 0;
spinAnimation.removedOnCompletion = NO;
spinAnimation.delegate = self;
spinAnimation.timingFunction = [CAMediaTimingFunction functionWithName:
kCAMediaTimingFunctionEaseOut];
[spinWheel.layer addAnimation:spinAnimation forKey:#"spinAnimation"];
[CATransaction commit];
}
Use this:
[UIView animateWithDuration:0.1 animations:^{
CGAffineTransform transform = CGAffineTransformMakeRotation(1.0);
transform = CGAffineTransformRotate(transform, -180);
ImageView.transform = transform;
} completion:^(BOOL finished) {
CGAffineTransform transform = CGAffineTransformMakeRotation(0);
transform = CGAffineTransformRotate(transform,0);
ImageView.transform = transform;
}];

CGAffineTransform rotation and resize on slider value

I am using Slider to Resize and Rotate-
For the Rotate -
CGAffineTransform transform = editingView.transform;
transform = CGAffineTransformMakeRotation(sliderVal * 2*M_PI / 30);
editingView.transform = transform;
For the Resize-
CGAffineTransform t = CGAffineTransformMakeScale(sliderVal/30, sliderVal/30);
CGPoint center = editingView.center;
[UIView animateWithDuration:0.5
animations:^{
editingView.transform = t;
editingView.center = center;
}
completion:^(BOOL finished) {
}];
Using the above code,Both working fine separately.
But I have to resize the rotated view,Or rotate the resized view.
I saw many suggestions coming separate behavior because i am using CGAffineTransformMakeRotation,CGAffineTransformMakeScale,If i use the CGAffineTransformScale,CGAffineTransformRotation then my problem will be solve.
The problem is when I am using CGAffineTransform then scaling is not proper,View disappears from the screen.
You're setting transformation matrix of the view with editingView.transform line.
You should change your code for rotate:
CGAffineTransform transform = editingView.transform;
transform = CGAffineTransformMakeRotation(sliderVal * 2*M_PI / 30);
editingView.transform = CGAffineTransformConcat(editingView.transform, transform);
and for resize:
CGAffineTransform t = CGAffineTransformMakeScale(sliderVal/30, sliderVal/30);
CGPoint center = editingView.center;
[UIView animateWithDuration:0.5
animations:^{
editingView.transform = CGAffineTransformConcat(editingView.transform,t);
editingView.center = center;
}
completion:^(BOOL finished) {
}];
With CGAffineTransformConcat you add 2 transform matrixes together so you won't lose older transforms. You can use CGAffineTransformIdentity to reset the transform.
CGAffineTransform translate = CGAffineTransformMakeTranslation(self.webView.frame.origin.x,self.webView.frame.origin.y - self.webView.frame.size.height * 0.25);
CGAffineTransform scale = CGAffineTransformMakeScale(0.6, 0.6);
CGAffineTransform transform = CGAffineTransformConcat(translate, scale);
transform = CGAffineTransformRotate(transform, degreesToRadians(-10));
[UIView beginAnimations:#"MoveAndRotateAnimation" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:2.0];
editingView.transform = transform;
[UIView commitAnimations];
Try like this...

Objective-c Control Transform Rotation

I have an image grid that I am zooming in and zooming out on click of the image. All is working fine, but I am having trouble controlling the rotation of the CGAffineTransform. I thought I could pass in the angle to control how my rotation is determined, but when I do so, the transform will not zoom in and I am left zoomed out.
I feel that I have missed the proper implementation of this along somewhere during creating my routine, so if anyone can point out where I went wrong I would appreciate it
Here is my code
float angle = -1.661799;
if(status == 0){
[UIView animateWithDuration:1.5f delay:0.0f
options:UIViewAnimationOptionCurveEaseIn animations:^{
CGAffineTransform totalTransform =
CGAffineTransformMakeTranslation(-middleX , -middleY );
totalTransform = CGAffineTransformScale(totalTransform, 3.5f, 3.5f);
totalTransform = CGAffineTransformTranslate(totalTransform, middleX , middleY );
//totalTransform = CGAffineTransformMakeRotation(angle);
[self.view setTransform:totalTransform];
}completion:^(BOOL finished) {
}];
status++;
}else{
[UIView animateWithDuration:1.3f delay:0.0f
options:UIViewAnimationOptionCurveEaseIn animations:^{
CGAffineTransform tr = CGAffineTransformMakeScale(1.00 ,1.00);
[self.view setTransform:tr];
}completion:^(BOOL finished) {
[UIView animateWithDuration:1.3f delay:0.0f
options:UIViewAnimationOptionCurveEaseIn animations:^{
CGAffineTransform totalTransform =
CGAffineTransformMakeTranslation(-middleX , -middleY );
totalTransform = CGAffineTransformScale(totalTransform, 3.5f, 3.5f);
totalTransform = CGAffineTransformTranslate(totalTransform, middleX , middleY );
//totalTransform = CGAffineTransformMakeRotation(angle);
[self.view setTransform:totalTransform];
}completion:^(BOOL finished) {}];
}];
status = 0;
}
This is an old question--but in case anyone comes back to it:
When you are doing a series of transforms, you need to use the right call. There are two calls for each type of transform (rotate, translate, scale). One is used for combinations of transforms, and the other is for making a new transform.
The first call can be a "Make" call. The subsequent calls need to be the non-make variety.
"Make" call, which generates a transformation matrix:
CGAffineTransformMakeRotation(angle)
non-make call, which modifies an existing transformation matrix:
CGAffineTransformRotate(existingMatrix, angle)
so, from your code:
CGAffineTransform totalTransform =
CGAffineTransformMakeTranslation(-middleX , -middleY );
totalTransform = CGAffineTransformScale(totalTransform, 3.5f, 3.5f);
totalTransform = CGAffineTransformTranslate(totalTransform, middleX , middleY );
totalTransform = CGAffineTransformMakeRotation(angle);
Your first call created a matrix, as is appropriate. However your rotation call (the 4th call) should be:
totalTransform = CGAffineTransformRotate(totalTransform, angle);
Otherwise, as you noticed, you discard all the transformations before that call, and only get rotation, in this case, or whatever your last transformation would be.

how can I interrupt/stop animation when I rotate?

For example, I use the animation in landscape status, duration is 5.0s, from status A to B; in the middle of the 5.0s, I may rotate the iPad from landscape to portrait. I want the animation stopped and make the UI status to C after I rotated.
I'm not sure my question is clear.
How can I do that?
my animation code:
- (void)moveImage:(UIImageView *)image duration:(NSTimeInterval)duration x:(NSNumber*)dx y:(NSNumber*)dy
{
// Setup the animation
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:duration];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationBeginsFromCurrentState:YES];
// The transform matrix
float fx = [dx floatValue];
float fy = [dy floatValue];
CGAffineTransform transform = CGAffineTransformMakeTranslation(fx, fy);
//CGAffineTransform transform = CGAffineTransformMakeRotation(0.4);
//CGAffineTransform transform = CGAffineTransformMakeScale(2.0, 2.0);
image.transform = transform;
// Commit the changes
[UIView commitAnimations];
}
Starting and Stopping Explicit Animations has a section on starting and stopping core animations
willRotateToInterfaceOrientation:duration notifies you when the rotation begins.
So all have to do is 1) from 2)

Resources