I want to scale+translate a view and then animate this transformation back. But CGAffineTransformInvert returns a transformation that does something different (cannot understand the logic of it).
#import <UIKit/UIKit.h>
@interface TestView : UIView {
UIView *view;
CGAffineTransform transform;
}
@end
#import "TestView.h"
#import <QuartzCore/QuartzCore.h>
@implementation TestView
- (void)testAnimation:(NSString*)animationID finished:(NSNumber*)finished context:(void*)context {
CGAffineTransform transformInverted = CGAffineTransformInvert(transform);
[UIView beginAnimations:@"test2" context:NULL];
[UIView setAnimationDuration:3.0];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
view.transform = transformInverted;
[UIView commitAnimations];
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
view = [[UIView alloc] initWithFrame:CGRectMake(150, 150, 100, 100)];
view.backgroundColor = [UIColor greenColor];
[self addSubview:view];
CGAffineTransform transform1 = CGAffineTransformTranslate(view.transform, -150, -150);
transform = CGAffineTransformScale(transform1, (float)1/2, (float)1/2);
[UIView beginAnimations:@"test1" context:NULL];
[UIView setAnimationDuration:3.0];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(testAnimation:finished:context:) ];
view.transform = transform;
[UIView commitAnimations];
}
return self;
}