解锁第二屏 Objective c
Unlock second screen Objective c
我有一个锁定屏幕的应用程序,现在我尝试在多个屏幕上使用它。我不知道解锁第二个屏幕。
这是我解锁第二个屏幕的方法:
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];
}
我成功解锁了第一个屏幕但没有第二个屏幕,如果有人可以帮助我...
如果有人需要我用下面的代码修复它:
.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];
}
}
我有一个锁定屏幕的应用程序,现在我尝试在多个屏幕上使用它。我不知道解锁第二个屏幕。 这是我解锁第二个屏幕的方法:
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];
}
我成功解锁了第一个屏幕但没有第二个屏幕,如果有人可以帮助我...
如果有人需要我用下面的代码修复它:
.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];
}
}