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不影响已打开的窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-18 12:51