views:

27

answers:

3

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?

+1  A: 

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).

Tim van Elsloo
A: 

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;
}
Michael Waterfall
that has only the effect that now the background is drawn before it is transformed. So the hick in the animation is now not at the end of the animation it's now at the beginning.
V1ru8
Oh okay. Check this answer out, think it's what you're looking for: http://stackoverflow.com/questions/818207/uiview-scaling-during-animation
Michael Waterfall
A: 

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.

V1ru8