使用 UIScreen 驱动 VGA 显示器 - 似乎没有显示 UIWindow?
您好,
我正在尝试使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您需要初始化窗口...
You need to init your window...
[newwindow makeKeyAndVisible];
?[newwindow makeKeyAndVisible];
?我认为你的问题是外部显示器。在代码外部创建一个视图控制器(也许只需添加新文件 ViewController 并将内容放入 .xib 中)并尝试一下,以确保视图控制器在将其调用到外部显示器之前正常工作。这是您的代码以及我建议的更改 - [mainViewController view] 是您在外部创建的视图控制器。
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.
只是在这里记录一下,以防有人偶然发现这个问题。在我意识到我的应用程序委托必须保留 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.
我已将示例 .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
需要指出的是,本页和 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.