Question

J'essaie de prendre en charge l'affichage externe sur mon application iOS sans utiliser de fichiers .xib.

En ce moment, mon code contient ceci:

- (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];
}

Lorsque j'exécute cela, l'écran de sortie du téléviseur se fermera immédiatement. Si je commente cette ligne:

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

L'écran de sortie du téléviseur fonctionnera correctement, mais bien sûr, je ne vois rien sur mon écran de simulateur.

Quelqu'un a-t-il une idée de ce que je devrais faire?Merci d'avance!

Était-ce utile?

La solution

Je peux vous suggérer d'essayer l'exemple de code source de code TVOUT sur github - https://github.com/johngoodstadt/tvout.

Il utilise un code similaire à la vôtre mais emballé dans une classe que vous pouvez copier et appeler à partir de votre propre code.

Il devrait résoudre votre problème d'affichage.En passant, je ne ferais pas votre code dès que dans les "Didfinishlaunchingwithoptions", mais plus tard dans le premier contrôleur d'affichage.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top