我必须将外部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];
答案 0 :(得分:2)
我找到了解决方案。 问题是当外部屏幕连接到iOS设备时,必须更改屏幕的模式。
[[NSNotificationCenter defaultCenter] addObserver: self selector:@selector(screenDidConnectNotification:) name: UIScreenDidConnectNotification object: nil];
应在screenDidConnectNotification函数中更改屏幕模式。