objective-c - 使用 NSBezierPath addClip - 如何反转剪辑

标签 objective-c macos mask clip nsbezierpath

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

相关文章:

ios - Watchkit app 控制音量父 iOS

ios - 我是否需要在 Thread 中运行 AudioServicesCreateSystemSoundID

objective-c - Xcode 崩溃 - 但仅针对特定项目(目标 'MyApp' 已被要求提供其构建上下文,但它不属于项目)

ios - 掩码 SKSpriteNode

css - 如何使用 css mix-blend-mode 在 svg 图像上方制作黑色但白色的文本

ios - 如何在应用程序中实现 'User' 功能?

PHP:无法加载动态库 intl.so (OSX)

objective-c - 为什么使用 MKLocalSearch 会返回错误并且无法加载预期结果?

objective-c - 如何在 Mac OS X 中获取相对于窗口的光标位置?

html - CSS:背景颜色和图标 - 反转蒙版