2015-06-22 2 views
0

Я стараюсь изо всех сил отражать экран приложения iPad на внешнем дисплее. Я знаю, что он делает это автоматически, просто используя AirPlay и Mirror после выбора Apple TV, однако этот метод всегда делает его почтовым ящиком и не занимает весь экран. Я просто хочу, чтобы он отражал точный контент с iPad, но занимал весь экран Apple TV. В коде для AppDelegate.h:Внешний внешний вид iOS Неправильная ориентация

#import <UIKit/UIKit.h> 
@class MainView; 
@class ViewController2; 
@interface AppDelegate : UIResponder <UIApplicationDelegate> { 
    UIWindow *window; 
    UINavigationController *tabBarController; 
    ViewController2 *_remoteVC; 

} 

@property (nonatomic, retain) IBOutlet UIWindow *window; 
@property (nonatomic, retain) IBOutlet UINavigationController *tabBarController; 
@property (strong, atomic) UIWindow *secondWindow; 
@end 

AppDelegate.m:

@implementation AppDelegate 
@synthesize tabBarController; 
@synthesize window, secondWindow; 

- (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); 
     _remoteVC = [[ViewController2 alloc] initWithNibName:nil bundle:nil]; 
     tabBarController = [[UINavigationController alloc] init]; 
     self.secondWindow.rootViewController = tabBarController; 
     [self.secondWindow makeKeyAndVisible]; 

     // Show the window. 
     self.secondWindow.hidden = NO; 
    } 
} 

- (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. 
     _remoteVC = [[ViewController2 alloc] initWithNibName:nil bundle:nil]; 
     tabBarController = [[UINavigationController alloc] init]; 
     self.secondWindow.rootViewController = tabBarController; 
    } 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 { 
    sleep(1.5); 

    [window setRootViewController:tabBarController]; 
    [self setUpScreenConnectionNotificationHandlers]; 

    [self checkForExistingScreenAndInitializeIfPresent]; 
return YES; 

В разделе Общие параметры для моего проекта, я только Landscape Left проверяется на ориентации. Приложение - приложение для iPad только с использованием MainWindow.xib и без раскадровки. Все ViewControllers находятся внутри MainWindow.xib, ни один из классов не имеет собственного .xib-файла. Когда я AirPlay это или использую внешний дисплей Simulator, экраны iPad и внешнего дисплея выглядят так: enter image description here enter image description here Как вы можете видеть, похоже, что зеркальное отображение внешнего дисплея работает, поскольку оно показывает тот же цвет, что и фиолетовый, панель навигации имеет, но, может быть, ориентация просто неверна? Я не разрешаю авторотацию в каких-либо контроллерах представления и не изменяю никаких настроек. Что я делаю не так?

ответ

0

Я думаю, что проблема здесь:

'_remoteVC = [[ViewController2 alloc] initWithNibName:nil bundle:nil]; 
    tabBarController = [[UINavigationController alloc] init]; 
    self.secondWindow.rootViewController = tabBarController;' 

Вы инициализировать контроллер представления навигации без установки RootViewController. Вы должны установить tabBarController.rootViewController = _remoteVC;