问题
I'm writing a Cocoa application which should work in fullscreen mode. I would like to detect the user setting the application window to fullscreen mode. In Xcode,
- in the Attributes Inspector, Full Screen value is "Primary Window"
- in the File Inspector, Use Auto Layout is unchecked
- the view of the main window has Autoresizes Subviews unchecked
I'm making the AppDelegate an NSWindowDelegate like this in AppDelegate.h
@interface AppDelegate : NSObject <NSApplicationDelegate, NSWindowDelegate>
and have a method like this in AppDelegate.m
-(void) windowDidEnterFullScreen:(NSNotification *)notification
{
vuMain.view.frame = NSMakeRect(0, 0, window.frame.size.width,
window.frame.size.height);
NSLog(@"AppDelegate - windowDidEnterFullScreen");
}
But this method is not getting called as there is no NSLog output. A watch set in the method does not get reached.
What am I doing wrong? What am I missing?
Please help! I'm rather new to Cocoa and am struggling for one full day with this. Thanks
回答1:
You need to actually make the AppDelegate
the window's delegate. You either have to connect the window's delegate
outlet to the AppDelegate
in the NIB, or you need to set the window's delegate
property programmatically.
来源:https://stackoverflow.com/questions/30280025/cocoa-windowdidenterfullscreen-not-being-called