1

According to this answer there's a way to make a CGAffineTransform permanent:

iphone - making the CGAffineTransform permanent

but it's not explained... the answer tells about a copy that is generated by the animation but isn't clear how to get it and assign to the original object, so this is the code, how to make it permanent?

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3];

[UIView setAnimationRepeatAutoreverses:NO];
[UIView setAnimationRepeatCount:1];

[UIView setAnimationDelegate:self];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];

float angleRadians = 180 * ((float)M_PI / 180.0f);
CGAffineTransform t = CGAffineTransformMakeRotation(angleRadians);

self.myView.transform = t;
[self.myView setCenter:CGPointMake(160, 220)];

[UIView commitAnimations];

Thanks

Community
  • 1
  • 1
Enlil
  • 1,027
  • 14
  • 28

2 Answers2

1

You can try going a level down to Core Animation and apply transform animation with following properties:

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform"];
animation.fromValue = [NSValue valueWithCATransform3D: t];
animation.toValue = [NSValue valueWithCATransform3D: t];
animation.duration = 0.0;
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeBoth;
[yourView.layer addAnimation:animation forKey:@"transform"];

Then you can do other core animations and it should retain the transform. Don't forget to import QuartzCore framework.

Bartosz Ciechanowski
  • 10,293
  • 5
  • 45
  • 60
  • Are you sure you are passing CATransform3D and not CGAffineTransform? – Bartosz Ciechanowski Aug 31 '11 at 22:09
  • This works if you define t like this: CATransform3D t = CATransform3DMakeAffineTransform(CGAffineTransformMakeRotation(angleRadians)); Although the key portion, in answer to the question is setting animation.removedOnCompletion to NO. – Alex S Aug 10 '12 at 20:29
0

In iOS 4.0 or greater Apple recommends using Block based animations

reference: What are block-based animation methods in iPhone OS 4.0?

    [UIView animateWithDuration:0.3 
                      delay:0 
                    options:UIViewAnimationOptionCurveEaseOut 
                 animations:^{ self.myView.transform = CGAffineTransformMakeRotation(M_PI) } 
                 completion:NULL];

Not sure if this will solve your problem exactly, but it is a step in the right direction.

Community
  • 1
  • 1
Silvae
  • 594
  • 1
  • 8
  • 20
  • the animation block works, but when i pinch to zoom the view come back to original state – Enlil Sep 01 '11 at 16:11
  • Was your pinch-to-zoom mechanism created by you? If so, applying a new transformation (e.g. scaling to make it larger) would override the rotation if you used the method CGAffineTransformMakeScale as opposed to CGAffineTransformScale – Silvae Sep 01 '11 at 17:24