使用drawAsPatternInRect绘制图像时如何忽略变换:
我使用以下代码在视图中绘制背景图像:
CGContextRef currentContext = UIGraphicsGetCurrentContext(); CGContextSaveGState(currentContext);
UIImage *image = [UIImage imageNamed:@"background.jpg"]; [图像drawAsPatternInRect:矩形];
CGContextRestoreGState(currentContext);
这效果很好。但是,当我更改动画视图的大小时,绘制的图像会缩放,直到重新绘制。我怎样才能在动画过程中忽略这种转变?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
目前我认为这是不可能的。由于 iPhone 没有非常快的处理器,Apple 选择禁用 LiveRedraw 功能(该功能实际上在 Mac 上可用)。
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).
尝试将视图的
contentMode
设置为UIViewContentModeRedraw
。Try setting the view's
contentMode
toUIViewContentModeRedraw
.我终于找到了解决办法。我使用 contentMode UIViewContentModeTopLeft 因此它不会缩放。在调整动画大小之前,我仅在新尺寸大于旧尺寸时才重新绘制。动画结束后我总是重画。
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.