使用 NSBezierPath addClip 仅将绘图限制在用于裁剪的路径内。我想做相反的事情 - 只在外面画画。
- (void)drawRect:(NSRect)dirtyRect {
NSBezierPath *dontDrawInThis = ...;
//We want an opposite mask of [dontDrawInThis setClip];
//Drawing comes here
}
最佳答案
这是我的解决方案:
- (void)drawRect:(NSRect)dirtyRect {
NSBezierPath *dontDrawInThis = ...;
// The mask is the whole bounds rect, subtracted dontDrawInThis
NSBezierPath *clip = [NSBezierPath bezierPathWithRect:self.bounds];
[clip appendBezierPath:dontDrawInThis.bezierPathByReversingPath];
[clip setClip];
//Drawing comes here
}
对于 iOS,将 NSRect 替换为 CGRect。
关于objective-c - 使用 NSBezierPath addClip - 如何反转剪辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41219816/