iPadアプリの画面を外部ディスプレイにミラーリングするために最善を尽くしています。Apple TV を選択した後に AirPlay と Mirror を使用するだけでこれが自動的に行われることはわかっていますが、この方法では常にレターボックスになり、画面全体を占有しません。私は単純に、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;
プロジェクトの [一般設定] で、[方向] に対して [横向き] のみをオンにしました。このアプリは、MainWindow.xib を使用し、ストーリーボードを使用しない iPad 専用アプリです。すべての ViewControllers は MainWindow.xib 内にあり、どのクラスにも独自の .xib ファイルはありません。AirPlay または Simulator External Display を使用すると、iPad と External Display の画面は次のよう
になります。間違っているだけですか?どのView Controllerでも自動回転を許可しておらず、設定も変更していません。私は何を間違っていますか?