最小化可可NSWindow没有标题栏

最小化可可NSWindow没有标题栏

本文介绍了最小化/最小化可可NSWindow没有标题栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被卡住了!显然是因为我在这里发布问题.

I'm stuck! Obviously... because I'm posting a question here.

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

I have built my own custom window controls for my OS X / cocoa app. The close button works great -- no problems. The minimize button doesn't work at all when I disable the titlebar.

因此,当标题栏如上图所示打开时,我点击了此方法,则最小化效果很好:

So when the title bar is on like the image above and I hit this method, the minimizing works fine:

ViewController.h

@interface ViewController : NSViewController {

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

}
@end

ViewController.m

@implementation ViewController

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

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

    -(IBAction)terminate:(id)sender {
        [NSApp terminate:self];
    }
@end

然后,如果我禁用标题栏,则该方法将停止工作.没有错误,没事.我已经尝试过:[[NSApp mainWindow] miniaturize:nil];[[NSApp mainWindow] performMiniaturize:self];.两者都不起作用.实际上...如果标题栏处于打开状态,两者都可以工作.但是,一旦我关闭它,就不会起作用.

Then if I disable the title bar, that same method stops working. No errors, nothing. I've tried both: [[NSApp mainWindow] miniaturize:nil]; and also [[NSApp mainWindow] performMiniaturize:self];. Neither of which worked. Actually... the both work IF the title bar is on. But once I turn it off, neither work.

想法/评论?

哦,我正在使用Storyboards,Xcode 7,并且将10.10定位为目标,并使用10.11 SDK(如果有关系的话).

Oh, I'm using Storyboards, Xcode 7, and am targeting 10.10 and using the 10.11 SDK if that matters at all.

谢谢.

推荐答案

您必须保留原始的交通灯"按钮并手动隐藏它们.

You have to keep the original "traffic light" buttons around and hide them manually.

这是我配置窗口的方式:

Here's how I've configured the window:

self.titleVisibility = NSWindowTitleHidden;
self.titlebarAppearsTransparent = YES;
self.movableByWindowBackground = YES;

这就是我隐藏交通信号灯的方式:

And here's how I've hidden the traffic lights:

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];
            }
        }
    }
}

在此处查看示例项目.

这篇关于最小化/最小化可可NSWindow没有标题栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 10:01