在 NSCollectionViews 子视图上绘制
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先绘制视图,然后在其上绘制所有子视图。无法在
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’sdrawRect:
method.