setCollectionBehavior不影响已打开的窗口 [英] setCollectionBehavior not taking affect on already opened window

查看:421
本文介绍了setCollectionBehavior不影响已打开的窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用户在我的应用程序中单击在10秒内获取屏幕截图"按钮.然后,用户将另一个应用程序聚焦并使其全屏显示.当用户专注于此全屏应用程序时,我的10秒计时器现在变为0.我的应用程序打开一个全尺寸显示器的窗口,并在其上绘制屏幕截图.但是现在我希望窗口显示在所有空间上.我试过了:

A user clicks a "take screenshot in 10seconds" button in my application. Then user focuses another app and makes it full screen. While user is focused in this full screen app, my 10sec timer now hits 0. My application opens a window that is full size of monitor, it draws the screenshot on it. But now I want the window to show on all spaces. I tried this:

[window setCollectionBehavior:(16 | 1 | 256)];

但是,这并没有使窗口显示在用户当前的空间上(哪个是全屏应用程序),你们知道发生了什么吗?

But it is not making the window show over the users current space (Which is the full screen app) do you guys know whats up?

只需验证一下,这些常量的幻数是:

Just to verify, the magic numbers for these constants are:

var NSWindowCollectionBehaviorStationary = 1 << 4; // 16
var NSWindowCollectionBehaviorCanJoinAllSpaces = 1 << 0; // 1
var NSWindowCollectionBehaviorFullScreenAuxiliary = 1 << 8; // 256
var NSWindowCollectionBehaviorMoveToActiveSpace = 1 << 1;// 2

这是正确的吗?我通过ctypes进行此操作,因此必须使用幻数.

Is this correct? I am doing this via ctypes so have to use magic numbers.

我也尝试过:

 [window setCanBeVisibleOnAllSpaces:YES]

但这没用.

谢谢

因此,该窗口已经打开,我无法访问下面a2的答案中提到的情节提要等,我们在聊天中对其进行了讨论,我们需要以某种方式进行讨论以使这种影响生效,是否有人有任何想法?

So this window is already opened and I dont have access to the storyboard etc as mentioned in a2's answer below, we discussed it in chat and we need to hook into it somehow to make this take affect, is there anyone with any ideas?

推荐答案

您需要将此代码添加到xib/情节提要中,或者您的NSWindowController子类-windowDidLoad方法中,或者您指定的NSWindow子类:

You need to add this code either in your xib / storyboard, either in your NSWindowController subclass -windowDidLoad method, either in your designated initialiser of your NSWindow subclass :

- (void) awakeFromNib { 
    [self setCollectionBehavior:NSWindowCollectionBehaviorCanJoinAllSpaces]; 
}

OR

- (id)initWithContentRect:(NSRect)contentRect
                styleMask:(NSUInteger)styleMask
                  backing:(NSBackingStoreType)bufferingType
                    defer:(BOOL)flag {
    if (self = [super initWithContentRect:contentRect styleMask:styleMask  backing:bufferingType defer:flag]) {
        [self setCollectionBehavior:NSWindowCollectionBehaviorCanJoinAllSpaces];
    }
    return self;
}

或者如果您有NSWindowController

- (void)windowDidLoad {
    [super windowDidLoad];

    [[self window] setCollectionBehavior:NSWindowCollectionBehaviorCanJoinAllSpaces];
}

或编辑nib文件,然后将此行为添加到XCode的窗口中.

OR Edit the nib file and add this behaviour to your window in XCode.

这篇关于setCollectionBehavior不影响已打开的窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆