やっぱり久々なポストです。
iPadでは外部映像出力が可能なので、それを試しているのですが、ちょっと解らずハマっていた事があったのでメモ程度に書いておきますね。デバッグするのも困難ですし。
基本的な実装の手順としては、下記の通りです。
1. つながっているスクリーンを[UIScreen screens]がNSArrayで取得する。
2. 1.で取得したUIScreenからお好みのUIScreenModeを取得する。
3. UIScreenを取得する。
4. 取得したUIScreenのcurrentModeに2.で取得した内容を設定する。
5. 表示させたいコンテンツを作成する。
6. 外部出力させるためにUIWindowを作る。
7. 6.に表示させたいコンテンツをaddSubView: する。
8. window.screen に3.のUIScreenを設定する。
9. windowの基礎的な設定を行う。
以上です。
——————————————
// ログとして外部モニターに表示する内容
// log message displayed in external monitor.
NSMutableString *str = [[NSMutableString alloc] init];
int screenCount = [[UIScreen screens] count];
// 設定されるスクリーンモード
// used screen mode
UIScreenMode *current = nil;
// checking each screen information
for(int i = 0; i < screenCount; i++)
{
int modelen = [[[[UIScreen screens] objectAtIndex:i] availableModes] count];
// checking each screen mode in screen.
for (int j = 0; j < modelen; j++)
{
// getting screen mode
UIScreenMode *curMode = [[[[UIScreen screens] objectAtIndex:i] availableModes]
objectAtIndex:j];
// get information of screen.
NSString *sstr = [NSString stringWithFormat:@"screen:%i, mode:%i, w:%f, h:%f,
ratio:%f ---", i, j, current.size.width, current.size.height,
current.pixelAspectRatio];
[str appendString:sstr];
// if curMode.size.width is larger than current, change current reference
if(curMode.size.width > current.size.width){
current = curMode;
}
}
}
// screen object
UIScreen *another = [[UIScreen screens] objectAtIndex:1];
another.currentMode = current;
CGSize size = current.size;
uvc = [[UIViewController alloc] init];
// create new window.
UIWindow *window = [[UIWindow alloc] initWithFrame:CGRectMake(
0.0f,
0.0f,
size.width,
size.height
)];
UITextView *tv = [[UITextView alloc] initWithFrame:CGRectMake(
0.0f, 0.0f, 800.0f, 800.0f)
];
[uvc.view addSubview:tv];
tv.text = str;
[tv release];
[window addSubview:uvc.view];
window.screen = another;
[window makeKeyAndVisible];
[window setHidden:NO];
—————————————————
※syntaxhighlighterをうまくつかえていないので改行をくわえています。
ちなみにgithubにのせてますのでご興味のある方はご覧下さい。
http://github.com/mmlemon/iPad-external-display-sample
何か間違いやご不明な点があればお気軽にご質問下さいね!