1

.xibファイルを使用せずにiOSアプリで外部表示をサポートしようとしています。

現在、私のコードには次のものが含まれています。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ 
    if ([[UIScreen screens] count] > 1){
        externalScreen = [[UIScreen screens] objectAtIndex:1];
        UIScreenMode *current = [[[[UIScreen screens]objectAtIndex:1]availableModes]objectAtIndex:0];
        externalScreen.currentMode = current;
        externalWindow = [[UIWindow alloc] initWithFrame:[externalScreen bounds]];
        externalWindow.screen = externalScreen;
        externalWindow.clipsToBounds = YES;

        extController = [[ExternalController alloc] init];
        [externalWindow addSubview:extController.view];
        [externalWindow makeKeyAndVisible];
    }
    self.window = [[UIWindow alloc] initWithFrame:[[[UIScreen screens] objectAtIndex:0] bounds]];

    mainController = [[ViewController alloc] init];
    [self.window addSubview:mainController.view];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
}

これを実行すると、TVOut画面がすぐに閉じます。この行にコメントすると:

//self.window = [[UIWindow alloc] initWithFrame:[[[UIScreen screens] objectAtIndex:0] bounds]];

TV Out画面は正常に機能しますが、もちろんシミュレーター画面には何も表示されません。

誰かが私が何をすべきか考えていますか?前もって感謝します!

4

1 に答える 1

3

GITHubでサンプルソースコードTVOutを試してみることをお勧めします-https ://github.com/JohnGoodstadt/TVOut

それはあなたのものと同様のコードを使用しますが、あなたがコピーしてあなた自身のコードから呼び出すことができるクラスにパッケージ化されています。

表示の問題を解決するはずです。ちなみに、私はあなたのコードを「didFinishLaunchingWithOptions」のように早くはしませんが、後で最初のViewControllerで行います。

于 2012-09-17T12:45:36.620 に答える