我正在尝试仅绘制一个自定义部分UIImage
(即:我想reveal的部分UIImage
用户触摸)并且我通过使用得到了合理的结果mask
的财产layer
.
我的身上有这样的东西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 中绘制图像的自定义部分(可以是任何形状)的最佳方法是什么?.
您可以尝试的一件事是简单地剪切而不是创建额外的图层。例如
- (void)drawRect:(CGRect)rect
{
CGContextRef ctx = UIGraphicsGetCurrentContext();
UIBezierPath *maskPath = [UIBezierPath bezierPath];
[maskPath setLineWidth:10.0];
[maskPath moveToPoint:CGPointMake(10.0, 10.0)];
[maskPath addLineToPoint:CGPointMake(100.0, 100.0)];
CGContextAddPath(ctx, maskPath.CGPath);
CGContextClip(ctx)
[img drawInRect:rect];
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)