CGAffineTransformMakeScale Makes UIView Jump to Original Size before scale

Viewed 21908

I have a UIView that I set up to respond to pinch gestures and change its size, except, once you enlarge it and then try and pinch it again, it jumps to its original size (which just so happens to be 100x200). Here is the code:

@implementation ChartAxisView


- (id)initWithFrame:(CGRect)frame {
    if ((self = [super initWithFrame:frame])) {
        // do gesture recognizers
        UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(onPinch:)]; 
        [self addGestureRecognizer:pinch]; 
        [pinch release];
    }
    return self;
}

- (void)drawRect:(CGRect)rect {
    CGContextRef context = UIGraphicsGetCurrentContext();

    CGColorRef redColor = [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:1.0].CGColor;

    CGContextSetFillColorWithColor(context, redColor);
    CGContextFillRect(context, self.bounds);
}

- (void)onPinch: (UIPinchGestureRecognizer*) gesture {  
    self.transform = CGAffineTransformMakeScale(gesture.scale, gesture.scale);
}

- (void)dealloc {
    [super dealloc];
}


@end

Any thoughts?

3 Answers

you can set transform with following code:

ivClone setTransform:CGAffineTransformMakeScale(scale, scale)];

and you can get current transform with following coee:

newV.transform.a //x scale
newV.transform.d // y scale
Related