Using NSBezierPath addClip - How to invert clip

2019-07-26 02:26发布

Using NSBezierPath addClip only limits drawing to inside the path used for clipping. I'd like to do the opposite - Only draw outside.

- (void)drawRect:(NSRect)dirtyRect {
    NSBezierPath *dontDrawInThis = ...;

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

    //Drawing comes here
}

1条回答
女痞
2楼-- · 2019-07-26 02:55

This was my solution:

- (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
}

For iOS replace NSRect with CGRect.

查看更多
登录 后发表回答