Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animate Rotation/Scale/Translate of UIImage at the same time

I am new to objective-c and I want to add an image to the screen, tweening it like in AS3, moving it from one end to the other of the screen while rotating around its own center point.

I tried with

[UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
            // TRANSFORM SCREENSHOT
            screenShotView.transform = CGAffineTransformRotate(screenShotView.transform, -M_PI * 0.05);
            screenShotView.transform = CGAffineTransformScale(screenShotView.transform, 0.6, 0.6);
            screenShotView.transform = CGAffineTransformTranslate(screenShotView.transform, 
                                                                  self.webView.frame.origin.x,
                                                                  self.webView.frame.origin.y - self.webView.frame.size.height * 0.3
                                        );

but with this code the image rotates around the center of the TransformIdentity. So while rotating and moving the rotation gets out of controll and the image isn't exactly at the position I loved it to be.

What is the right way to rotate and translate at the same time, translating the rotation center with the image?

and at least after transformation I want to add a close button to the right upper corner of the image. for that I need the new coordinates of the corner, too.

thnx!

like image 657
headkit Avatar asked Mar 08 '12 17:03

headkit


1 Answers

I now ended with the following code, but I still don't know if this is the state of the art solution.

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];

    screenShotView.transform = transform;

[UIView commitAnimations];
like image 163
headkit Avatar answered Oct 05 '22 22:10

headkit