views:

23

answers:

1

Here's a follow up to a previous question. My code below animates a square by scaling it and rotating it. It does this by making a rotation transform and adding a scale transform to it. That works fine. When it's done, it calls throbReset. I used to have throbReset just set self's transform to a CGAffineTransformMakeScale and that would unscale it, but would also unrotate it. So I tried starting with the current transform and adding the unscale to it, but now it doesn't do anything (visible).


CGColorRef color = [[colorArray objectAtIndex:colorIndex] CGColor];
 [UIView beginAnimations:nil context:NULL];
 [UIView setAnimationDelegate:self];
 [UIView setAnimationDuration:0.5f];
 [UIView setAnimationDidStopSelector:@selector(throbReset:context:)];
//  [[self layer] setFillMode:kCAFillModeForwards]; // apparently not needed
 CGAffineTransform xForm = CGAffineTransformMakeScale(2.0, 2.0);
 xForm = CGAffineTransformRotate(xForm, M_PI / 4);
 [self setTransform:xForm];
 [[self layer] setBackgroundColor:color];
 [UIView commitAnimations];
}

- (void)throbReset:(NSString *)animationID context:(void*)context {
 NSLog(@"-%@:%s fired", [self class], _cmd);
 [UIView beginAnimations:nil context:NULL];
 [UIView setAnimationDuration:2.0];
 CGAffineTransform xForm = [self transform];
 xForm = CGAffineTransformScale(xForm, 1.0, 1.0);
 [self setTransform:xForm];
 [UIView commitAnimations];
}
A: 

You are just scaling to the same size since you are basically saying take the current transform and scale it 1:1 on X and 1:1 on Y. You might want to do 0.5,0.5 instead of 1.0,1.0 in your second method.

CGAffineTransform xForm = [self transform];
xForm = CGAffineTransformScale(xForm,0.5, 0.5);

Keep in mind when you add the rotation to do it in reverse order, so rotate then scale. This would be more important if you involved a translation but in this case would probably work either way.

Ben
So if I had just set my `transform` property to `CGAffineTransformMakeScale(1.0, 1.0)` would it not have gone back to the original size? I don't quite get the difference between `CGAffineTransformMakeScale` and `CGAffineTransformScale` I guess. I mean I understand what the arguments are, but not the underlying functionality.
Steve
You are operating relatively on the transform you specify in the CGAffine function call, so TransformScale scales the input relative to itself. In this case you input the current transform, which gets scaled 1:1. I'm not sure on the MakeScale difference, perhaps it assumes the identity transform as the input transform.
Ben