use*_*452 5 ios airplay apple-tv
目前,我为iPhone/iPad制作的任何应用都可以通过AirPlay镜像到Apple TV.但是,即使在横向模式下,它也只占据屏幕的中央部分,左侧和右侧都是黑色.以Real Racing HD这样的应用程序的方式,将它全部转移到AirPlay全屏是什么?
编辑:根据一个建议,我添加了我正在使用的所有代码,而不是告诉secondWindow正常使用相同的根视图控制器,我设置了一个不同颜色的新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
Run Code Online (Sandbox Code Playgroud)
和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;
}
Run Code Online (Sandbox Code Playgroud)
将其变成 AirPlay 全屏涉及到什么...
如果您想直接深入了解,可以从这里开始了解 iOS 世界中的 Windows 和屏幕: https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/WindowAndScreenGuide/UsingExternalDisplay/UsingExternalDisplay.html
如果您想首先获得更广泛的概述,这里是包含视频和其他教程/文档的聚合页面:
https://developer.apple.com/airplay/
[编辑] 这是我正在设置第二个显示器的应用程序的代码摘录。我从给你的链接中获取了大部分内容。注意:“主”适用于设备,“远程”适用于电视。
笔记:此代码尚未完成生产;仍有一些状态变化它没有响应。在运行此命令之前,请连接到 AirPlay 接收器并打开镜像。
我有这个:
@interface AppDelegate () {
SFCManagerMainViewController *_mainVC;
SFCRemoteMonitorViewController *_remoteVC;
}
@end
Run Code Online (Sandbox Code Playgroud)
标题:
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UIWindow *secondWindow;
Run Code Online (Sandbox Code Playgroud)
和这个:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[self setUpScreenConnectionNotificationHandlers];
[self checkForExistingScreenAndInitializeIfPresent];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
_mainVC = [[SFCManagerMainViewController alloc] initWithNibName:nil bundle:nil];
self.window.rootViewController = _mainVC;
[self.window makeKeyAndVisible];
return YES;
}
- (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 = [[SFCRemoteMonitorViewController alloc] initWithNibName:nil bundle:nil];
self.secondWindow.rootViewController = _remoteVC;
[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 = [[SFCRemoteMonitorViewController alloc] initWithNibName:nil bundle:nil];
self.secondWindow.rootViewController = _remoteVC;
} 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;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2192 次 |
| 最近记录: |