views:

13

answers:

1

In the following UIView animation block, I do a CGAffineTransformMakeScale and a CGAffineTransformMakeRotation, and though the duration is set to 1.0f, the scale goes really fast and the rotation goes in 1 second like it should.

It must be my lack of understanding about how AffineTransforms are applied but I can't figure it out.

What gives?

EDIT: Vladimir's answer worked great. I was changing the same property twice, rather than changing two properties. To make two changes to a transform property, you have to make a transform with the initial change, then add the second change to that transform and then set you object's transform from there. This way, you can chain as many together as you want.


CGColorRef color = [[colorArray objectAtIndex:colorIndex] CGColor];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0f];
[[self layer] setFillMode:kCAFillModeForwards];
[self setTransform:CGAffineTransformMakeScale(2.0, 2.0)];
[self setTransform:CGAffineTransformMakeRotation(M_PI / 4)];
[[self layer] setBackgroundColor:color];
[UIView commitAnimations];
+1  A: 
[self setTransform:CGAffineTransformMakeScale(2.0, 2.0)];
[self setTransform:CGAffineTransformMakeRotation(M_PI / 4)];

2nd line overrides the effect of 1st line. You should construct the whole transform and then apply it to your view:

CGAffineTransform tr = CGAffineTransformMakeScale(2.0f,2.0f);
tr = CGAffineTransformRotate(tr, M_PI/4);
[self setTransform: tr];
Vladimir
Works like a charm. Thanks, Vladimir! I figured it was something like that...
Steve