【问题标题】:Unlock second screen Objective c解锁第二个屏幕目标 c
【发布时间】:2016-09-03 21:30:09
【问题描述】:

我有一个锁定屏幕的应用程序,现在我尝试使用多个屏幕。我不知道解锁第二个屏幕。 这是我解锁第二个屏幕的方法:

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];


}

如果有人可以帮助我,我成功解锁了第一个屏幕但不是第二个屏幕...

【问题讨论】:

    标签: objective-c screen fullscreen unlock


    【解决方案1】:

    如果有人需要,我用以下代码修复它:

    .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;
    

    然后退出FullScreen:

    for(NSInteger index = 1; index < [windowArray count]; index ++){
    
                if([[windowArray objectAtIndex:index]contentView].inFullScreenMode){
    
                    [[[windowArray objectAtIndex:index]contentView] exitFullScreenModeWithOptions:nil];
    
                } 
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-28
      • 1970-01-01
      • 2019-05-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多