我正在尝试在所有屏幕上显示窗口副本。请参阅下面的代码。它仅在主屏幕上正确显示无边框窗口。我在任何地方都看不到另一个窗口。
窗口应该从左侧显示 200 像素,从顶部显示 200 像素。
我将 origin.x 设置为屏幕高度 - 300(= 200px 间距 + 100px 窗口本身的高度)。
知道我做错了什么吗?
- (void)displayOnAllScreens
{
NSArray *screenArray = [NSScreen screens];
_tempWindows = [[NSMutableArray alloc] init];
if ([screenArray count] == 1) {
[self displayOnScreen:[NSScreen mainScreen]];
} else {
for (int i=0; i<[screenArray count]; i++) {
[self displayOnScreen:[screenArray objectAtIndex:i]];
}
}
}
- (void)displayOnScreen:(NSScreen *)screen
{
BOOL isMainScreen = NO;
if (screen == [NSScreen mainScreen]) {
isMainScreen = YES;
}
NSRect screenRect = [screen frame];
NSRect frame = NSMakeRect(screenRect.origin.x + 200, screenRect.size.height - 300, 100, 100);
NSWindow *_tempWindow;
_tempWindow = [[NSWindow alloc] initWithContentRect:frame
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered
defer:NO];
if (isMainScreen) {
[_tempWindow setBackgroundColor:[NSColor lightGrayColor]];
} else {
[_tempWindow setBackgroundColor:[NSColor redColor]];
}
[_tempWindow makeKeyAndOrderFront:NSApp];
[_tempWindow setAlphaValue:0.93];
[_tempWindow setCollectionBehavior:NSWindowCollectionBehaviorCanJoinAllSpaces];
[_tempWindows addObject:_tempWindow];
}