最小化/小型化可可 NSWindow 没有标题栏

Dre*_*rew 5 macos xcode cocoa objective-c nswindow

我被困住了!显然...因为我在这里发布了一个问题。

我为我的 OS X / cocoa 应用程序构建了自己的自定义窗口控件。关闭按钮效果很好——没问题。当我禁用标题栏时,最小化按钮根本不起作用。

在此输入图像描述

因此,当标题栏像上图一样打开并且我点击此方法时,最小化效果很好:

视图控制器.h

@interface ViewController : NSViewController {

    - (IBAction)minimize:(id)sender;        
    @property (strong) IBOutlet NSButton *btn_minimize;

}
@end
Run Code Online (Sandbox Code Playgroud)

视图控制器.m

@implementation ViewController

    - (void)viewDidLoad {
        [super viewDidLoad];
    }

    - (IBAction)minimize:(id)sender {
      [[NSApp mainWindow] performMiniaturize:self];
    }

    -(IBAction)terminate:(id)sender {
        [NSApp terminate:self];
    }
@end
Run Code Online (Sandbox Code Playgroud)

然后,如果我禁用标题栏,相同的方法将停止工作。没有错误,什么都没有。我已经尝试过:[[NSApp mainWindow] miniaturize:nil];[[NSApp mainWindow] performMiniaturize:self];. 两者都不起作用。实际上...如果标题栏打开,两者都可以工作。但一旦我把它关掉,这两种方法都不起作用。

标题栏已关闭

没有标题栏的应用程序

想法/评论?

哦,我正在使用 Storyboards、Xcode 7,并且目标是 10.10,并使用 10.11 SDK(如果这很重要的话)。

提前致谢。

Gui*_*mbo 5

您必须保留原来的“红绿灯”按钮并手动隐藏它们。

这是我配置窗口的方式:

self.titleVisibility = NSWindowTitleHidden;
self.titlebarAppearsTransparent = YES;
self.movableByWindowBackground = YES;
Run Code Online (Sandbox Code Playgroud)

这是我隐藏交通灯的方法:

for (id subview in self.contentView.superview.subviews) {
    if ([subview isKindOfClass:NSClassFromString(@"NSTitlebarContainerView")]) {
        NSView *titlebarView = [subview subviews][0];
        for (id button in titlebarView.subviews) {
            if ([button isKindOfClass:[NSButton class]]) {
                [button setHidden:YES];
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

请参阅此处的示例项目