我有UIView
with backgroundColor
set with colorWithPatternImage
。正如预期的那样,背景图像从左上角开始绘制。
当我renderInContext
在该视图上进行操作时出现问题:背景图像是从左下角开始绘制的。其他一切似乎都很好。
这是源图像和目标图像:
这是代码:
// here is the layer to be rendered into an image
UIView *src = [[UIView alloc] initWithFrame:(CGRect){{0, 0}, {100, 100}}];
src.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]];
[self.view addSubview:src];
// here we'll display the image
UIImageView *dest = [[UIImageView alloc] initWithFrame:(CGRect){{110, 0}, src.bounds.size}];
[self.view addSubview:dest];
// render `src` to an image in `dest`
UIGraphicsBeginImageContext(src.bounds.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[src.layer renderInContext:context];
dest.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
有没有办法让图像以正确的方向平铺,就像在src
视图中一样?