我有一个nsview,我使用绘制矩形为背景绘制图像。它也有3个子视图nsbuttons。问题是,只要鼠标停在按钮上,其他按钮就会消失。但是,当我删除绘制矩形方法时,这不会发生。所以我猜测这与绘制图像的绘制矩形方法有关。NSView drawRect干扰子视图?
我该如何避免这种情况? 谢谢。编号: 好吧,我想出了问题出在哪里。基本上,我有一个NSMenuItem,我用3个按钮在里面放一个视图。但在NSMenu中,顶部有4个像素的填充。所以,基本上,以去除填充我用这里提供的解决方案: Gap above NSMenuItem custom view
从溶液中有一个在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];
}
你可以发布你的自定义'drawRect:'吗? – 2011-04-21 20:23:07
发布drawRect方法。谢谢。 – user635064 2011-04-21 21:02:19