首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用NSBezierPath addClip -如何反转剪辑

使用NSBezierPath addClip -如何反转剪辑
EN

Stack Overflow用户
提问于 2016-12-19 17:50:56
回答 2查看 870关注 0票数 3

使用NSBezierPath addClip仅将绘图限制在用于剪切的路径内部。我想做相反的事情--只在外面画画。

代码语言:javascript
复制
- (void)drawRect:(NSRect)dirtyRect {
    NSBezierPath *dontDrawInThis = ...;

    //We want an opposite mask of [dontDrawInThis setClip];

    //Drawing comes here
}
EN

回答 2

Stack Overflow用户

发布于 2016-12-19 17:50:56

这是我的解决方案:

代码语言:javascript
复制
- (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。

票数 3
EN

Stack Overflow用户

发布于 2019-12-08 00:39:27

@avishic's answer的Swift版本

代码语言:javascript
复制
override func draw(_ dirtyRect: NSRect) {
    super.draw(dirtyRect)
    let restrictedPath = NSBezierPath()

    // fill the restricted path with shapes/paths you want transparent...

    let fullRect = NSBezierPath(rect: self.bounds)
    fullRect.append(restrictedPath.reversed)
    fullRect.setClip()
    NSColor.blue.setFill()

    frame.fill()
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41219816

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档