Search code examples
objective-ciphoneuiimagequartz-graphics

How to ignore transformations when drawing an image with drawAsPatternInRect:


I draw a background image in a view with the following code:

CGContextRef currentContext = UIGraphicsGetCurrentContext(); CGContextSaveGState(currentContext);

UIImage *image = [UIImage imageNamed:@"background.jpg"]; [image drawAsPatternInRect:rect];

CGContextRestoreGState(currentContext);

This works well. But when I change the size of that view animated the drawn image is scaled until it get's redraw. How can I ignore this transformation during the animation?


Solution

  • I finally found a solution. I use contentMode UIViewContentModeTopLeft so it doesn't get scaled. And before the resize animation I only redraw if the new size is greater then the old one. And after the animation I always redraw.