self.myPath=[UIBezierPath bezierPathWithArcCenter:center
radius:200
startAngle:0
endAngle:180
clockwise:YES];
(我能够通过一些网络搜索开始运行)。
我有这条路。现在我想填充这条路径的反面,所以留下这部分并填充其他所有内容。我怎样才能完成编码?我没有太多这方面的信息。
问题
之前使用 Cemal Answer 后显示的区域只显示一个带有红色描边的圆圈。
编辑
- (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+):
Creates and returns a new bezier path object with the reversed contents of the current path.
所以要反转你的路径,你只需:
UIBezierPath* aPath = [UIBezierPath bezierPathWithArcCenter:center
radius:200
startAngle:0
endAngle:180
clockwise:YES];
self.myPath = [aPath bezierPathByReversingPath];
关于ios - 如何获取 UIBezierPath 的反向路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11191353/