开发者

How to make my app stay on top of fullscreen apps

I have an app which must always stay on top of other applications. I'm currently using the setLevel property for the main window to keep it on top of other desktop applications.

I'm trying to fix my app so it can also st开发者_如何学运维ay on top of full-screen apps in Lion. Any ideas on how this can be done?

The Application delegate looks like this:

#import "alwaysOnTopAppDelegate.h"

@implementation alwaysOnTopAppDelegate

@synthesize window;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    [window setLevel:NSFloatingWindowLevel];
}

@end


Found the answer: The app delegate should look like this:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    [window setLevel:kCGMainMenuWindowLevel-1];
    [window setCollectionBehavior:NSWindowCollectionBehaviorStationary|NSWindowCollectionBehaviorCanJoinAllSpaces|NSWindowCollectionBehaviorFullScreenAuxiliary];
}


The way that Yoink works is simple: Just set "Application is Agent (UIElement)" to YES in the Info.plist for your application. It will mean it doesn't show in the dock etc. but that's probably fine for an auxiliary window (well, it was for me!). It probably makes sense to provide a menu bar item in this case so the user can stop the application easily.


follow is my test code, it work ok, hope can help.

NSPanel *test_panel = [[NSPanel alloc] initWithContentRect:NSMakeRect(300, 300, 500, 500) styleMask:NSTitledWindowMask|NSClosableWindowMask backing:NSBackingStoreBuffered defer:YES];
[test_panel setReleasedWhenClosed:YES];
[test_panel setHidesOnDeactivate:NO];
[test_panel setFloatingPanel:YES];
[test_panel setStyleMask:NSBorderlessWindowMask | NSNonactivatingPanelMask];
[test_panel setLevel:kCGMainMenuWindowLevel-1];
[test_panel  setCollectionBehavior:NSWindowCollectionBehaviorCanJoinAllSpaces|NSWindowCollectionBehaviorFullScreenAuxiliary];
[test_panel setCanBeVisibleOnAllSpaces:YES];
[test_panel center];
[test_panel orderFront:nil];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜