cocoa windowDidEnterFullScreen not being called

落花浮王杯 提交于 2020-01-03 01:59:05

问题


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,

  1. in the Attributes Inspector, Full Screen value is "Primary Window"
  2. in the File Inspector, Use Auto Layout is unchecked
  3. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!