我有一个锁定屏幕的应用程序,现在我尝试使用多个屏幕。我不知道解锁第二个屏幕。 这是我如何解锁第二个屏幕:
if([[NSScreen screens] count] > 1){
// Draw a new window to fill the screen
NSScreen *screen;
NSRect screenRect = CGRectMake(0, 0, screen.frame.size.width , screen.frame.size.height);
NSWindow *secondaryMonitorWindow = [[NSWindow alloc] initWithContentRect:screenRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO screen:screen];
[secondaryMonitorWindow.contentView exitFullScreenModeWithOptions:nil];
}
我成功解锁了第一个屏幕而不是第二个屏幕,如果有人可以帮助我......
答案 0 :(得分:0)
如果有人需要我使用以下代码修复它:
的.m
[windowArray insertObject:self.window atIndex:0];
//if we have many screens
NSRect screenRect;
NSArray *screenArray = [NSScreen screens];
for (NSInteger index = 1; index < [screenArray count]; index++)
{
NSScreen *screen = [screenArray objectAtIndex: index];
screenRect = CGRectMake(0, 0, screen.frame.size.width , screen.frame.size.height);
NSWindow *window = [[NSWindow alloc] initWithContentRect:screenRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO screen:screen];
[window.contentView setWantsLayer:YES];
window.contentView.layer.backgroundColor = [NSColor blackColor].CGColor;
[window.contentView enterFullScreenMode:[[NSScreen screens] objectAtIndex:index] withOptions:nil];
[windowArray addObject:window];
}
别忘了加入.h
NSMutableArray *windowArray;
并退出全屏:
for(NSInteger index = 1; index < [windowArray count]; index ++){
if([[windowArray objectAtIndex:index]contentView].inFullScreenMode){
[[[windowArray objectAtIndex:index]contentView] exitFullScreenModeWithOptions:nil];
}
}