1
votes

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?

3

3 Answers

2
votes

At the moment I don't think that's possible. Since the iPhone doesn't have a very fast processor Apple choose to disable the LiveRedraw-feature (that actually is available on Mac).

1
votes

Try setting the view's contentMode to UIViewContentModeRedraw.

- (id)initWithFrame:(CGRect)frame {
    if ((self = [super initWithFrame:frame])) {

        // Get the view to redraw when it's frame is changed
        self.contentMode = UIViewContentModeRedraw;

    }
    return self;
}
1
votes

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.