2

我必须将外部 UIScreen 的模式设置为以 1024x768 分辨率运行。首先我搜索屏幕是否支持此分辨率:

if ([[UIScreen screens] count] > 1){

    CGSize size1024;
    size1024.height = 0;
    size1024.width  = 0;
    UIScreenMode *screenMode1024 = nil;
    UIScreen *secondScreen = [[UIScreen screens] objectAtIndex:1];

    for(int i = 0; i < [[secondScreen availableModes] count]; i++)
    {
       UIScreenMode *current = [[[[UIScreen screens] objectAtIndex:1] availableModes] objectAtIndex: i];
       if (current.size.width == 1024.0 && current.size.height == 768.0)
       {
           size1024 = current.size;
           screenMode1024 = current;
           break;
       }
    }
}

之后,我将外部屏幕的模式设置为使用此分辨率,但不知何故它不起作用并且屏幕正在使用其他默认分辨率。

secondScreen.currentMode = screenMode1024;
UIWindow *secondWindow = [[UIWindow alloc] initWithFrame: CGRectMake(0,0, size1024.width, size1024.height)];
secondWindow.screen = secondScreen;

...


secondWindow.hidden = NO;

有什么帮助吗?也许我错过了一些设置?我也试过这个:

[[[UIScreen screens] objectAtIndex:1] setCurrentMode:screenMode1024];
4

1 回答 1

2

我找到了解决方案。问题是,当外部屏幕连接到 iOS 设备时,必须更改屏幕的模式。

[[NSNotificationCenter defaultCenter] addObserver: self selector:@selector(screenDidConnectNotification:) name: UIScreenDidConnectNotification object: nil];

应在 screenDidConnectNotification 函数中更改屏幕模式。

于 2013-11-06T13:35:55.330 回答