use*_*064 5 cocoa objective-c nsview drawrect nsbutton
我有一个nsview,我使用绘制矩形绘制背景图像.它还有3个子视图nsbuttons.问题是,只要鼠标按下按钮,其他按钮就会消失.但是当我删除draw rect方法时,这不会发生.所以我猜这与绘制图像的draw rect方法有关.
我怎么能避免这个?谢谢.
编辑:好的,我想出了问题所在.基本上,我有一个NSMenuItem,我用3个按钮在其中放置一个视图.但在NSMenu中,顶部有一个4像素的填充.所以,基本上,删除那个填充我使用了这里提供的解决方案: NSMenuItem自定义视图上方的差距
从解决方案中,drawRect方法中有一行:
[[NSBezierPath bezierPathWithRect:fullBounds] setClip];
Run Code Online (Sandbox Code Playgroud)
那一刻,我删除了这一行,按钮表现正常.但是,顶部的填充物不会消失.
这是我的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];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2146 次 |
| 最近记录: |