Неправильная ориентация внешнего дисплея iOS

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

#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;

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


person user717452    schedule 22.06.2015    source источник


Ответы (1)


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

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

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

person Alain    schedule 14.10.2015