你好呀,

我正在尝试使用 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;
 }
有帮助吗?

解决方案

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

 UIWindow *newwindow = [[UIWindow alloc] init];

其他提示

[newwindow makeKeyAndVisible];?

我觉得你的问题是externalDisplay。创建你的代码外的视图控制器(也许做一个简单的添加新的文件视图控制器,并把东西在的.xib),并尝试一下,以确保视图 - 控制工作你怎么称呼它到外部显示器前。这里是你的代码我建议的更改 - [mainViewController视图]是您创建外视图 - 控制

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

就在对这个问题的情况下,任何人都跌倒在这里记录本。我没能得到任何第二屏幕上显示出来,直到我意识到,我的应用程序委托有保留的UIWindow。它没有天然的所有者,所以,如果你只是做一个普通的自动释放,窗口会之前它曾经显示器发布。

希望有所帮助。

我上传样品.xcodeproj到github上。

我refered这个页为主。

非常感谢。 :)

http://github.com/igaiga/iPadDisplayOutSample

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

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

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top