NSView drawRect干扰子视图?
|
我有一个nsview,我使用draw rect绘制背景图像。它还具有3个子视图nsbutton。问题是,每当鼠标按下按钮时,其他按钮就会消失。但是,当我删除draw rect方法时,这不会发生。因此,我猜测这与绘制图像的draw rect方法有关。
如何避免这种情况?
谢谢。
编辑:
好的,我知道问题出在哪里。基本上,我有一个NSMenuItem,并在其中带有3个按钮的视图。但是在NSMenu顶部,填充为4个像素。因此,基本上,要删除该填充,我使用了此处提供的解决方案:
NSMenuItem自定义视图上方的间隙
在解决方案中,drawRect方法中有一行:
[[NSBezierPath bezierPathWithRect:fullBounds] setClip];
此刻,我删除了这一行,并且按钮正常运行。但是然后,顶部的填充不会消失。
这是我的drawRect:
- (void) drawRect:(NSRect)dirtyRect {
[[NSGraphicsContext currentContext] saveGraphicsState];
NSRect fullBounds = [self bounds];
fullBounds.size.height += 4;
[[NSBezierPath bezierPathWithRect:fullBounds] setClip];
NSImage *background = [NSImage imageNamed:@\"bg.png\"];
[background drawInRect:fullBounds fromRect:NSZeroRect operation:NSCompositeCopy fraction:100.0];
[[NSGraphicsContext currentContext] restoreGraphicsState];
}
没有找到相关结果
已邀请:
2 个回复
骇毖煽洁铂
超可林