如何获取UIBezierPath的反向路径 [英] How to Get the reverse path of a UIBezierPath
问题描述
self.myPath=[UIBezierPath bezierPathWithArcCenter:center
radius:200
startAngle:0
endAngle:180
clockwise:YES];
(这一点我能够通过网络搜索开始运行)。
(This much I was able to get up running with some web searching).
我有这条路。现在我想填补这条路径的反面,所以留下这部分并填充其他所有内容。我怎样才能完成编码?我没有太多信息。
I have this path. Now I want to fill the reverse of this path, so leaving this portion and filling everything else. How can I finish the coding? I don't have much info on this.
使用Cemal后显示的区域以前只显示红色笔划的圆圈。
The area it is showing after using Cemal Answer previously it only showed a circle with red stroke.
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor whiteColor];
self.punchedOutPath =
[UIBezierPath bezierPathWithOvalInRect:CGRectMake(50, 50, 400, 400)];
self.fillColor = [UIColor redColor];
self.alpha = 0.8;
}
return self;
}
- (void)drawRect:(CGRect)rect
{
[[self fillColor] set];
UIRectFill(rect);
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSetBlendMode(ctx, kCGBlendModeDestinationOut);
[[self punchedOutPath] fill];
CGContextSetBlendMode(ctx, kCGBlendModeNormal);
}
推荐答案
使用 bezierPathByReversingPath
。来自文档(仅限iOS 6.0+):
Use bezierPathByReversingPath
. From the docs (iOS 6.0+ only):
创建并返回一个新的贝塞尔曲线路径对象,其中包含当前路径的反转内容。 / p>
Creates and returns a new bezier path object with the reversed contents of the current path.
所以要改变你的路径,你只需:
so to reverse your path, you'd just:
UIBezierPath* aPath = [UIBezierPath bezierPathWithArcCenter:center
radius:200
startAngle:0
endAngle:180
clockwise:YES];
self.myPath = [aPath bezierPathByReversingPath];
这篇关于如何获取UIBezierPath的反向路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!