我正在尝试绘制
在我的
然后,在
UIImage
的自定义部分(即:我想要展示用户触摸的部分 UIImage
),并且通过使用layer
的mask
属性,我已经取得了合理的结果。在我的
UIView
上实现如下:UIBezierPath *maskPath = [UIBezierPath bezierPath];
[maskPath setLineWidth:10.0];
[maskPath moveToPoint:CGPointMake(10.0, 10.0)];
[maskPath addLineToPoint:CGPointMake(100.0, 100.0)];
CAShapeLayer *shapeMaskLayer = [CAShapeLayer layer];
shapeMaskLayer.path = maskPath.CGPath;
[self.layer setMask:shapeMaskLayer];
然后,在
drawRect
中:- (void)drawRect:(CGRect)rect
{
[img drawInRect:rect];
}
它起作用了。我只看到由maskPath
定义的图像部分。
然而,看起来这不是最好的解决方法。所以我的问题是:在iOS SDK中,绘制图像的任意形状的自定义部分的最佳方法是什么?