I'm stuck! Obviously... because I'm posting a question here.
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
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.
Thoughts / comments?
Oh, I'm using Storyboards, Xcode 7, and am targeting 10.10 and using the 10.11 SDK if that matters at all.
Thanks in advance.
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];
}
}
}
}
来源:https://stackoverflow.com/questions/33045075/minimize-miniaturize-cocoa-nswindow-without-titlebar