使用 UIScreen 驱动 VGA 显示器 - 似乎没有显示 UIWindow?

发布于 2024-08-29 03:18:49 字数 1412 浏览 9 评论 0原文

您好,

我正在尝试使用 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;
 }

HI there,

I'm trying to use UIScreen to drive a separate screen with the VGA dongle on my iPad.

Here's what I've got in my root view controller's 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;
 }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

锦欢 2024-09-05 03:18:49

您需要初始化窗口...

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

You need to init your window...

 UIWindow *newwindow = [[UIWindow alloc] init];
樱桃奶球 2024-09-05 03:18:49

[newwindow makeKeyAndVisible];

[newwindow makeKeyAndVisible];?

走走停停 2024-09-05 03:18:49

我认为你的问题是外部显示器。在代码外部创建一个视图控制器(也许只需添加新文件 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];
}

I think your problem is the externalDisplay. Create a viewcontroller outside your code (maybe do a simply Add new file ViewController and put stuff in the .xib) and try it out to make sure that viewcontroller is working before you call it into the external display. Here's your code with my suggested changes -- [mainViewController view] is the viewcontroller you created outside.

//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];
}
我要还你自由 2024-09-05 03:18:49

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

希望有帮助。

Just recording this here in case anyone stumbles on this question. I wasn't able to get anything to show up on the second screen until I realized that my app delegate had to retain the UIWindow. It has no natural owner, so if you just do a regular autorelease, the window will be released before it ever displays.

Hope that helps.

踏雪无痕 2024-09-05 03:18:49

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

我主要参考了这个页面。

多谢。 :)

http://github.com/igaiga/iPadDisplayOutSample

I've uploaded sample .xcodeproj into github.

I refered to this page mainly.

Thanks a lot. :)

http://github.com/igaiga/iPadDisplayOutSample

不疑不惑不回忆 2024-09-05 03:18:49

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

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

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

It needs to be mentioned that the code provided on this page and on the github link by igaiga is merely meant to "move" (NOT CLONE) the view that would normally be on the iPad (or other device).

If you need to clone (aka Mirror) the view and refresh its contents this link is more suitable: http://www.touchcentric.com/blog/archives/123

I hope this helps to clarify the use cases for both sets of code for users just starting to integrate video out capabilities into existing apps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文