我有一個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