В настоящее время любое приложение, которое я делаю для iPhone/iPad, можно отразить на Apple TV через AirPlay. Однако даже в ландшафтном режиме он занимает только центральную часть экрана с черным цветом слева и справа. Что вообще нужно для того, чтобы перевести его в полноэкранный режим AirPlay, как это сделали такие приложения, как Real Racing HD?
РЕДАКТИРОВАТЬ: В соответствии с предложением я добавил весь код, который я использую, и вместо того, чтобы указывать второму окну использовать тот же контроллер корневого представления, что и обычно, я настроил новый VC с другим цветом, чтобы увидеть, правильно ли настроена механика. . Это НЕ так, поскольку он по-прежнему выполняет обычное зеркалирование, даже если ему говорят использовать другой VC.
Вот AppDelegate.h
#import <UIKit/UIKit.h>
@class MainView;
@class ViewController;
@interface AppDelegate : UIResponder <UIApplicationDelegate> {
UIWindow *window;
UINavigationController *tabBarController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *tabBarController;
@property (nonatomic, retain) UIWindow *secondWindow;
@end
И соответствующие части AppDelegate.m
- (void)checkForExistingScreenAndInitializeIfPresent {
if ([[UIScreen screens] count] > 1) {
// Get the screen object that represents the external display.
UIScreen *secondScreen = [[UIScreen screens] objectAtIndex:1];
// Get the screen's bounds so that you can create a window of the correct size.
CGRect screenBounds = secondScreen.bounds;
self.secondWindow = [[UIWindow alloc] initWithFrame:screenBounds];
self.secondWindow.screen = secondScreen;
// Set up initial content to display...
NSLog(@"Setting up second screen: %@", secondScreen);
ViewController *mainView = [[ViewController alloc] init];
self.secondWindow.rootViewController = mainView;
[self.secondWindow makeKeyAndVisible];
// Show the window.
// self.secondWindow.hidden = NO;
}
NSLog(@"Screen count too low");
}
- (void)setUpScreenConnectionNotificationHandlers {
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserver:self selector:@selector(handleScreenDidConnectNotification:)
name:UIScreenDidConnectNotification object:nil];
[center addObserver:self selector:@selector(handleScreenDidDisconnectNotification:)
name:UIScreenDidDisconnectNotification object:nil];
}
- (void)handleScreenDidConnectNotification:(NSNotification*)aNotification {
UIScreen *newScreen = [aNotification object];
CGRect screenBounds = newScreen.bounds;
if (!self.secondWindow) {
NSLog(@"Initializing secondWindow/screen in notification");
self.secondWindow = [[UIWindow alloc] initWithFrame:screenBounds];
self.secondWindow.screen = newScreen;
// Set the initial UI for the window.
ViewController *mainView = [[ViewController alloc] init];
self.secondWindow.rootViewController = mainView;
} else {
NSLog(@"Second window already initialized.");
}
}
- (void)handleScreenDidDisconnectNotification:(NSNotification*)aNotification {
if (self.secondWindow) {
// Hide and then delete the window.
self.secondWindow.hidden = YES;
self.secondWindow = nil;
}
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[window setRootViewController:tabBarController];
[self setUpScreenConnectionNotificationHandlers];
[self checkForExistingScreenAndInitializeIfPresent];
return YES;
}