How to create a custom fieldless NSWindow in Objective-C + Cocoa?

Let me start by saying that this is my first real Cocoa application. This is a simple application that pretty much displays my site in a borderless window. So as I create a borderless window, use the following:

- (void) awakeFromNib { [window setStyleMask:NSBorderlessWindowMask]; [window setAcceptsMouseMovedEvents:YES]; [window setMovableByWindowBackground:YES]; [window setLevel:NSNormalWindowLevel]; } 

The problem is that as a result, the WebView inside the window does not skip the mouse over events on elements on the loaded page and does not provide the ability to enter text fields. I know that I have to create my own window instead and move the contents to it, but I'm too new to Objective-C to figure out how to do this.

I also tried declaring it all with no luck:

 @implementation specikAppDelegate @synthesize window; @synthesize webView; - (BOOL) canBecomeKeyWindow { return YES; } - (BOOL) canBecomeMainWindow { return YES; } - (BOOL) acceptsFirstResponder { return YES; } - (BOOL) becomeFirstResponder { return YES; } - (BOOL) resignFirstResponder { return YES; } ... @end 

In addition, I would like to be able to move the window by clicking and dragging it anywhere, but thought about it. I searched extensively on the Internet and cannot find a solution.

The contents of my .h file (just in case):

 @interface specikAppDelegate : NSObject <NSApplicationDelegate> { IBOutlet NSWindow *window; IBOutlet WebView *webView; } @property (assign) IBOutlet NSWindow *window; @property (nonatomic, retain) IBOutlet WebView *webView; - (IBAction)openAboutPanel:(id)sender; @end 

Any help would be appreciated, and as I said, I am a super newbie in the world of Objective-C and Cocoa, but I come from the background of PHP development.

+4
source share
2 answers

As explained in this answer , windows without a title or resizing (including windows without borders) cannot become key windows.

You were correct in overriding -canBecomeKeyWindow , but you missed the right place. You should not do this in the application deletion. You need to subclass NSWindow and then override this method.

+9
source

This apple code example should provide you with the necessary information, it is very easy to change the way it works and change it to your own Draw NSWindow (no frame: D)

http://developer.apple.com/library/mac/#samplecode/RoundTransparentWindow/Introduction/Intro.html

+3
source

Source: https://habr.com/ru/post/1339950/


All Articles