1
我最近问了一个关于在视图的drawRect方法中通过路径剪裁图像的问题。用路径剪切图像的不同部分
Krasnyk的代码如下复制。
- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGMutablePathRef path = CGPathCreateMutable();
//or for e.g. CGPathAddRect(path, NULL, CGRectInset([self bounds], 10, 20));
CGPathAddEllipseInRect(path, NULL, [self bounds]);
CGContextAddPath(context, path);
CGContextClip(context);
CGPathRelease(path);
[[UIImage imageNamed:@"GC.png"] drawInRect:[self bounds]];
}
它工作得很好。但是,当我的图像大于视图本身时,如何显示图像的不同部分?
我试着在椭圆和/或UIImage drawInRect的位置(显示为上边界)上进行调整,但是我无法解释一些复杂的效果(不需要的裁剪,奇怪的椭圆大小)。
编辑:也许我可以回答我自己的问题。我可以尝试drawAtPoint而不是drawInRect?或drawInRect并将原点设置为不同的位置,但同时扩大矩形的大小?
当我画一个更大的矩形比通过视图显示时,这会导致性能损失吗?