Cocoa app Create transparent view on top of all mac running applications
I am working on a mac osx application using Xcode. I would like to add a transparent full-screen view/window on top of all applications. So that I could ‘draw’ on the transparent view, and behind it will be whatever application, safari, word…etc.
I tried like the following
NSRect rect = [[NSScreen mainScreen] frame]; //this is full screen size, but still with the status bar like time, battery, etc. NSWindow *overlayWindow = [[NSWindow alloc]initWithContentRect:rect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]; overlayWindow.backgroundColor = [NSColor redColor]; [self.window addChildWindow:overlayWindow ordered:NSWindowAbove];
It’s a new full-screen child window of my mac-application. But it’s not on top of all applications i am running on my mac.
So my question,
How to add the view on top of my mac screen view(not only the top view of my application).
Thanks so much!!!
- #import in objective C: Am I doing this wrong?
- Get Xcode console output to log in a file
- Displaying file copy progress using FSCopyObjectAsync
- iPhone: fast hash function for storing web images (url) as files (hashed filenames)
- How do I tell iOS to download a file from iCloud Drive and get progress feedback
- Reduce image bytes size with Cocoa
3 Solutions Collect From Internet About “Cocoa app Create transparent view on top of all mac running applications”
See Apple’s FunkyOverlayWindow sample code. In addition to setting the window’s level, you will need to set its background color to clear and set it to non-opaque. If it’s transparent but you still want it to receive mouse events for drawing (rather than letting them pass through to the windows behind it), you’ll need to do
This looks like what you want.
With this useful predefined levels. Pick one you like. Add or subtract 1 if you want it just above or just below one of these levels.
#define NSNormalWindowLevel kCGNormalWindowLevel #define NSFloatingWindowLevel kCGFloatingWindowLevel #define NSSubmenuWindowLevel kCGTornOffMenuWindowLevel #define NSTornOffMenuWindowLevel kCGTornOffMenuWindowLevel #define NSMainMenuWindowLevel kCGMainMenuWindowLevel #define NSStatusWindowLevel kCGStatusWindowLevel #define NSModalPanelWindowLevel kCGModalPanelWindowLevel #define NSPopUpMenuWindowLevel kCGPopUpMenuWindowLevel #define NSScreenSaverWindowLevel kCGScreenSaverWindowLevel #define NSDockWindowLevel kCGDockWindowLevel
My problem was just because I didn’t set the self.window to the top layer. Then I add a childview(set to the top) to the self.window. It does nothing if I only set childview to top.
Ken and Steve’s answers have reasons. Thanks a lot.
- (setValue:) Cannot store object of type _SwiftValue at pictureURL. Can only store objects of type NSNumber, NSString, NSDictionary, and NSArray
- UITableViewSection Row Indices
- Getting user's default email address in Cocoa
- Amazon SNS Mobile Push – how to bulk subscribe endpoints to a topic?
- How to rotate a CGRect or CGImageCreateWithImageInRect?
- Clear CATiledLayers Cache When Changing Images
- Swift 3 WebView
- Execute an “if” condition “x” milliseconds and stop for “y”millisecond and repeat the condition ?
- When is tableView:numberOfRowsInSection: called in UITableView?
- How to Declare a Multidimensional Boolean array in Swift?
- What is void* and to what variables/objects it can point to
- How do I draw a cosine or sine curve in Swift?
- swift + OS X sandboxing: treat 'NSVBOpenPanel' as a 'NSOpenPanel' :: because I need to get the sender in the delegate method
- SIP library for iOS with non-GPL license
- How to use a pan gesture to rotate a camera in SceneKit using quaternions