Search code examples
xcodecocoauiviewcgaffinetransform

CGAffineTransform not working correctly


I want my transform to scale the image whilst translating it, is it possible to do in the same method?

    [UIView beginAnimations:annKey context:NULL];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDuration:duration];
    [UIView setAnimationCurve:curve];
    [UIView setAnimationBeginsFromCurrentState:YES];
    [UIView setAnimationDidStopSelector:@selector(animationFinished:finished:context:)];
    CGAffineTransform transform = CGAffineTransformMakeTranslation(x, y);
    CGAffineTransform scale = CGAffineTransformMakeScale(xx, yy);
    image.transform = scale;
    image.transform = transform;
    [UIView commitAnimations];

Solution

  • You have to concatenate the two transforms using CGAffineTransformConcat to translate and scale your view. You're currently just replacing the scale transformation with the translation.