UISCREENを使用してVGAディスプレイを駆動する - UiWindowが表示されないようですか?
-
27-09-2019 - |
質問
やあ、
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だと思います。コードの外側にViewControllerを作成し(新しいファイルViewControllerを追加して.xibに物を入れてください)、外部ディスプレイに呼び出す前にViewControllerが動作していることを確認してください。これが私の提案された変更のコードです - [MainViewController View]は、外で作成したViewControllerです。
//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を保持しなければならないことに気付くまで、2番目の画面に何も表示できませんでした。自然な所有者はいないので、通常のオートリリースを行うだけで、窓は表示される前にリリースされます。
それが役立つことを願っています。
サンプル.xcodeprojをgithubにアップロードしました。
主にこのページを参照しました。
どうもありがとう。 :)
このページとIgaigaによるGitHubリンクで提供されるコードは、通常iPad(または他のデバイス)にあるビューを「移動する」(クローンではない)ことを意図しているだけであることに言及する必要があります。
クローン(ミラー)をクローンする必要がある場合は、ビューとその内容を更新する必要がある場合、このリンクはより適しています。 http://www.touchcentric.com/blog/archives/123
これが、ビデオアウト機能を既存のアプリに統合し始めたばかりのユーザーの両方のコードセットのユースケースを明確にするのに役立つことを願っています。