Reputation: 454
I want to create an iPad app that besides the normal ipad screen (4:3) uses a second UIScreen containing a UIWindow in 16:9 widescreen format if a second screen is attached.
I use AppleTV for the connection.
I do not just want to mirror the ipad screen to the TV, because then it is just a 4:3 picture - i want to make it use the whole 16:9 widescreen.
So i started and got the second UIScreen set up and the window is now showing in widescreen format with green background on the TV.
//Check for Second Screen and if available, make a second UIWindow and put it on the second screen
NSArray* connectedScreens = [UIScreen screens];
NSInteger numberOfScreens = [[UIScreen screens]count];
NSLog(@"Number of screens connected: %d",numberOfScreens);
if (numberOfScreens > 1) {
//we have a second screen connected, display an extra window on the second screen
UIScreen* secondScreen = [connectedScreens lastObject];
UIWindow* secondWindow = [[UIWindow alloc]initWithFrame:secondScreen.bounds];
secondWindow.backgroundColor = [UIColor greenColor];
[secondWindow setScreen: secondScreen];
[secondWindow makeKeyAndVisible];
self.tvWindow = secondWindow;
}
so far so good.
But now i am not sure how to setup the navigation / view hierarchy.
I want to show the same data on both UIScreens (ipad + TV), just optimized for the different screen dimensions.
As i have exactly the same data that should be displayed and i don't want to have different instances of similar viewControllers floating around i thought i could use two xib files per ViewController, one for the 4:3 ipad view put into the 'view' property of the viewController and one xib for the 16:9 widescreen tv, put into the ‘tvView' property of the same viewController.
The ipad UIWindow has a UINavigationController rotating the different UIViewControllers.
So if i push a ViewController onto the ipad Window's Navigationcontroller, i could add the corresponding tvView from the TV-xib to the UIWindow of the TV Screen.
Am i on the right path here? How would you do this?
a little sketch: :)
Upvotes: 0
Views: 665
Reputation: 57149
That sounds about right. If you’re allowing user interaction with your navigation controller, you’ll have to register as the controller’s delegate
so you can keep track of what’s happening to your navigation stack on the iPad and swap out your TV views accordingly.
Upvotes: 0