开发者

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?


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


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;
}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜