Zig*_*rth 11 macos cocoa objective-c nswindow nsbutton
在我的应用程序中,我更改standardWindowButtons close/miniturize/expand的位置,如下所示:
 //Create the buttons
    NSButton *minitButton = [NSWindow standardWindowButton:NSWindowMiniaturizeButton forStyleMask:window.styleMask];
NSButton *closeButton = [NSWindow standardWindowButton:NSWindowCloseButton forStyleMask:window.styleMask];
NSButton *fullScreenButton = [NSWindow standardWindowButton:NSWindowZoomButton forStyleMask:window.styleMask];
//set their location
[closeButton setFrame:CGRectMake(7+70, window.frame.size.height - 22 - 52, closeButton.frame.size.width, closeButton.frame.size.height)];
[fullScreenButton setFrame:CGRectMake(47+70, window.frame.size.height - 22 -52, fullScreenButton.frame.size.width, fullScreenButton.frame.size.height)];
[minitButton setFrame:CGRectMake(27+70, window.frame.size.height - 22 - 52, minitButton.frame.size.width, minitButton.frame.size.height)];
//add them to the window
[window.contentView addSubview:closeButton];
[window.contentView addSubview:fullScreenButton];
[window.contentView addSubview:minitButton];
现在当窗口出现时带有按钮有两个问题:1.它们是灰色而不是正确的颜色2.当鼠标悬停在它们上面时,它们不显示+ - 或x符号
任何人都可以告诉我我做错了什么.谢谢.
Val*_*gin 10
这是这种悬停魔法的机制:在绘制自己标准的圆圈按钮(例如NSWindowMiniaturizeButton)之前调用它们的superview未记录方法_mouseInGroup:.如果此方法返回带YES圆圈的按钮,则会在里面显示图标.就这样.
如果将这些按钮放在自己的视图中,则可以简单地实现此方法并根据需要控制鼠标悬停外观.如果你只是移动或重新布局这些按钮,他们仍然是subview第NSThemeFrame(或类似的东西),你必须调酒方法_mouseInGroup:的这一课,可能是因为我们有非常简单的以前的方法确实不值得.
在我的情况下,我有自定义NSView包含我的标准按钮作为subviews和这个代码使上述所有描述魔术:
- (void)updateTrackingAreas
{
    NSTrackingArea *const trackingArea = [[NSTrackingArea alloc] initWithRect:NSZeroRect options:(NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways | NSTrackingInVisibleRect) owner:self userInfo:nil];
    [self addTrackingArea:trackingArea];
}
- (void)mouseEntered:(NSEvent *)event
{
    [super mouseEntered:event];
    self.mouseInside = YES;
    [self setNeedsDisplayForStandardWindowButtons];
}
- (void)mouseExited:(NSEvent *)event
{
    [super mouseExited:event];
    self.mouseInside = NO;
    [self setNeedsDisplayForStandardWindowButtons];
}
- (BOOL)_mouseInGroup:(NSButton *)button
{
    return self.mouseInside;
}
- (void)setNeedsDisplayForStandardWindowButtons
{
    [self.closeButtonView setNeedsDisplay];
    [self.miniaturizeButtonView setNeedsDisplay];
    [self.zoomButtonView setNeedsDisplay];
}
Sum*_*eja -1
调用[button highlight:yes]每个按钮。
| 归档时间: | 
 | 
| 查看次数: | 4647 次 | 
| 最近记录: |