0

除了镜像我的设备屏幕外,我没有让第二个显示器显示任何其他内容。我总是在电视上看到镜像的设备屏幕。这是我的代码,我希望有人可以帮助我。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];

[center addObserver:self selector:@selector(configureScreens) name:UIScreenDidConnectNotification object:nil];

[center addObserver:self selector:@selector(configureScreens) name:UIScreenDidDisconnectNotification object:nil];

[self configureScreens];

return YES;
}

-(void)configureScreens
{
NSUInteger screenCount = [[UIScreen screens] count];

NSLog(@"%u",screenCount);

if (screenCount == 1) {
    //single windows
}else if(screenCount == 2) {
    UIScreen *appleTvScreen = [[UIScreen screens] objectAtIndex:1];
    UIWindow *tvWindow = [[UIWindow alloc] initWithFrame:appleTvScreen.bounds];
    tvWindow.screen = appleTvScreen;
    tvWindow.backgroundColor = [UIColor redColor];

    tvWindow.rootViewController = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"tv"];

    tvWindow.hidden = NO;
}
}
4

1 回答 1

1

我可以建议您尝试 GITHub 上的示例源代码 TVOut - https://github.com/JohnGoodstadt/TVOut

它使用与您类似的代码,但打包在一个类中,您可以复制并从您自己的代码中调用该类。

它应该可以解决您的显示问题。

于 2012-09-17T12:41:25.080 回答