在 NSCollectionViews 子视图上绘制

发布于 2024-09-28 03:00:10 字数 574 浏览 0 评论 0原文

我在 NSCollectionView 子类中有以下代码:

-(void)drawRect:(NSRect)rect {  
    if(!NSEqualRects(highlightBox,NSZeroRect)) {        
        [[NSColor colorWithCalibratedRed:1.0f green:0.2f blue:0.2f alpha:1.0f] set];    
        NSRectFillUsingOperation(NSInsetRect(tempHighlightBox, -1.0, -1.0),NSCompositeSourceOver);
        [[NSColor colorWithCalibratedRed:0.2f green:0.2f blue:1.0f alpha:0.5f] set];
        NSRectFillUsingOperation(tempHighlightBox,NSCompositeSourceOver);
    }
}

NSRect 绘制正常,但它位于任何 NSCollectionViews 子视图后面,我希望它位于顶部。这可能吗?

I have the following code in an NSCollectionView subclass:

-(void)drawRect:(NSRect)rect {  
    if(!NSEqualRects(highlightBox,NSZeroRect)) {        
        [[NSColor colorWithCalibratedRed:1.0f green:0.2f blue:0.2f alpha:1.0f] set];    
        NSRectFillUsingOperation(NSInsetRect(tempHighlightBox, -1.0, -1.0),NSCompositeSourceOver);
        [[NSColor colorWithCalibratedRed:0.2f green:0.2f blue:1.0f alpha:0.5f] set];
        NSRectFillUsingOperation(tempHighlightBox,NSCompositeSourceOver);
    }
}

The NSRect is drawn ok, but it is behind any of the NSCollectionViews subviews and I would like it to be over the top. Is this possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

过度放纵 2024-10-05 03:00:10

首先绘制视图,然后在其上绘制所有子视图。无法在 drawRect: 方法中绘制子视图。为此,您还必须重写子视图的 drawRect: 方法。

A view is drawn first and then all its subviews are drawn over it. There is no way to draw over a subview in the drawRect: method. To do this you would also have to override the subview’s drawRect: method.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文