ПРИВЕТ там,
Я пытаюсь использовать UIScreen для управления отдельным экраном с аппаратным ключом VGA на моем iPad.
Вот то, что я вошел в свой корневой viewDidLoad контроллера представления:
//Code to detect if an external display is connected to the iPad.
NSLog(@"Number of screens: %d", [[UIScreen screens]count]);
//Now, if there's an external screen, we need to find its modes, itereate through them and find the highest one. Once we have that mode, break out, and set the UIWindow.
if([[UIScreen screens]count] > 1) //if there are more than 1 screens connected to the device
{
CGSize max;
UIScreenMode *maxScreenMode;
for(int i = 0; i < [[[[UIScreen screens] objectAtIndex:1] availableModes]count]; i++)
{
UIScreenMode *current = [[[[UIScreen screens]objectAtIndex:1]availableModes]objectAtIndex:i];
if(current.size.width > max.width);
{
max = current.size;
maxScreenMode = current;
}
}
//Now we have the highest mode. Turn the external display to use that mode.
UIScreen *external = [[UIScreen screens] objectAtIndex:1];
external.currentMode = maxScreenMode;
//Boom! Now the external display is set to the proper mode. We need to now set the screen of a new UIWindow to the external screen
external_disp = [externalDisplay alloc];
external_disp.drawImage = drawViewController.drawImage;
UIWindow *newwindow = [UIWindow alloc];
[newwindow addSubview:external_disp.view];
newwindow.screen = external;
}
Вам нужно запустить свое окно ...
UIWindow *newwindow = [[UIWindow alloc] init];
Думаю, ваша проблема - externalDisplay. Создайте viewcontroller вне вашего кода (возможно, просто добавьте новый файл ViewController и поместите материал в .xib) и попробуйте его, чтобы убедиться, что viewcontroller работает, прежде чем вы вызываете его на внешний дисплей. Вот ваш код с моими предложенными изменениями - [mainViewController view] - это контроллер представления, который вы создали снаружи.
//Code to detect if an external display is connected to the iPad.
NSLog(@"Number of screens: %d", [[UIScreen screens]count]);
//Now, if there's an external screen, we need to find its modes, iterate
//through them and find the highest one. Once we have that mode, break out,
//and set the UIWindow.
if([[UIScreen screens]count] > 1) //if there are more than 1 screens connected
//to the device
{
CGSize max;
UIScreenMode *maxScreenMode;
for(int i = 0; i < [[[[UIScreen screens] objectAtIndex:1] availableModes]count]; i++)
{
UIScreenMode *current = [[[[UIScreen screens]objectAtIndex:1]availableModes]objectAtIndex:i];
if(current.size.width > max.width);
{
max = current.size;
maxScreenMode = current;
}
}
//Now we have the highest mode. Turn the external display to use that mode.
UIScreen *external = [[UIScreen screens] objectAtIndex:1];
external.currentMode = maxScreenMode;
//Boom! Now the external display is set to the proper mode. We need to now
//set the screen of a new UIWindow to the external screen
UIWindow *newwindow = [UIWindow alloc];
[newwindow addSubview:[mainViewController view]];
newwindow.screen = external;
[newwindow makeKeyAndVisible];
[newwindow setHidden:NO];
}
Я загрузил пример .xcodeproj на github.
В основном я ссылался на эту страницу.
Thanks a lot. :)