开发者

How do I animate the simultaneous rotation and scaling of a view?

I have this view and I do some rotation transformation to it using something like

myView.transform = CGAffineTransformMakeRotation(degreesToRadian(90));
//The view was originally at 0开发者_如何学JAVA degrees.

at some other point of my code, I would like to scale the view animating it, so I do

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
myViews.transform = CGAffineTransformMakeScale(2.0f, 2.0f);
[UIView commitAnimations];

but when I do that the animation is performed as the view is at 0 degrees, ignoring the previous transformation. It simply assumes as the view is yet at zero degrees, so, this animation scales the view and rotates it back to 0 degrees (!!!!?????)

Is this some bug or am I missing something? thanks.


After discussing with KennyTM, I arrived at the best solutions for having both absolute transformations...

on the zoom method, I do:

// notice that both transformations are absolute
CGAffineTransform rotation = CGAffineTransformMakeRotation(degreesToRadian(viewAngle));
CGAffineTransform zoom = CGAffineTransformMakeScale(zoomFactor, zoomFactor);
myView.transform = CGAffineTransformConcat(rotation, zoom);

I store viewAngle when I rotate the view.


Because .transform assignment doesn't imply the new one will be concatenated to the old one. In your new transform, you only specifies a 200% scaling, but no rotations, so the view will return to 0°.

Try this instead:

myViews.transform = CGAffineTransformScale(myViews.transform, 2.0f, 2.0f);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜