6

你好呀,

我正在尝试使用 UIScreen 在我的 iPad 上使用 VGA 加密狗驱动一个单独的屏幕。

这是我在根视图控制器的 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;
 }
4

6 回答 6

8

你需要初始化你的窗口...

 UIWindow *newwindow = [[UIWindow alloc] init];
于 2010-04-19T13:57:57.057 回答
2

[newwindow makeKeyAndVisible];?

于 2010-04-17T23:36:30.480 回答
2

我认为你的问题是外部显示器。在您的代码之外创建一个视图控制器(也许只需简单地添加新文件 ViewController 并将内容放入 .xib 中)并尝试确保视图控制器在您将其调用到外部显示器之前工作。这是您的代码以及我建议的更改 - [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];
}
于 2010-07-09T20:58:11.953 回答
2

在这里记录一下,以防有人偶然发现这个问题。在我意识到我的应用程序委托必须保留 UIWindow 之前,我无法在第二个屏幕上显示任何内容。它没有自然所有者,因此如果您只是执行常规自动释放,则该窗口将在它显示之前被释放。

希望有帮助。

于 2011-05-10T22:52:16.400 回答
1

我已将示例 .xcodeproj 上传到 github。

我主要参考了这个页面。

非常感谢。:)

http://github.com/igaiga/iPadDisplayOutSample

于 2010-07-23T02:24:14.090 回答
0

需要指出的是,本页和 igaiga 在 github 链接上提供的代码仅用于“移动”(非克隆)通常在 iPad(或其他设备)上的视图。

如果您需要克隆(又名镜像)视图并刷新其内容,此链接更适合:http ://www.touchcentric.com/blog/archives/123

我希望这有助于为刚开始将视频输出功能集成到现有应用程序中的用户阐明两组代码的用例。

于 2010-11-02T13:28:51.957 回答