ios - 如何获取 UIBezierPath 的反向路径

标签 ios objective-c iphone uibezierpath

self.myPath=[UIBezierPath bezierPathWithArcCenter:center 
                                           radius:200 
                                       startAngle:0 
                                         endAngle:180 
                                        clockwise:YES];

(我能够通过一些网络搜索开始运行)。

我有这条路。现在我想填充这条路径的反面,所以留下这部分并填充其他所有内容。我怎样才能完成编码?我没有太多这方面的信息。

问题

enter image description here

之前使用 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);
}

enter image description here

最佳答案

使用 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/

相关文章:

ios - Swift:使用保护语句的好处?

ios - 我的快速代码不模拟

ios - 在 Swift 中截图并在顶部添加文本/水印

objective-c - Cocoa 在没有托管对象上下文的情况下无法执行操作

ios - CGImageCreateWithImageInRect 持有图像数据 - 泄漏?

iphone - Objective-C 中的快速枚举(循环)如何工作? (即: for (NSString *aString in aDictionary). ..)

ios - Alamofire异步请求在for循环中乱序发生

objective-c - objective-c 中的嵌套方法调用

ios - AVAudioSession 播放时录音奇怪的问题

带有 NSMutableArray 的 iphone EXC_BAD_ACCESS