【发布时间】:2014-01-05 03:07:47
【问题描述】:
我正在考虑将 AirPlay 功能添加到我的一个 ViewController 中。 View Controller 只显示一个 UIWebView。我想要做的是添加一个按钮,将这个内容镜像到 Apple TV。我知道可以进行系统范围的镜像,但它不会填满整个屏幕,周围有黑条。我一直在网上搜索,但我发现的大多数东西都是从 iOS 5 回来的,而且已经过时了。有人可以向我指出可以提供帮助的教程或嵌入式库的方向吗?我只需要它来镜像一个视图的内容,以便在 Apple TV 上全屏显示。
到目前为止,这是我所做的,但我相信它只创建了第二个窗口,没有在上面放任何东西。
在 AppDelegate 中,我为它创建了一个属性:
@property (nonatomic, retain) UIWindow *secondWindow;
在 AppDelegate 的 didFinish 方法中我运行:
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserver:self selector:@selector(handleScreenDidConnectNotification:)
name:UIScreenDidConnectNotification object:nil];
[center addObserver:self selector:@selector(handleScreenDidDisconnectNotification:)
name:UIScreenDidDisconnectNotification object:nil];
然后在 AppDelegate 我有:
- (void)handleScreenDidConnectNotification:(NSNotification*)aNotification
{
UIScreen *newScreen = [aNotification object];
CGRect screenBounds = newScreen.bounds;
if (!self.secondWindow)
{
self.secondWindow = [[UIWindow alloc] initWithFrame:screenBounds];
self.secondWindow.screen = newScreen;
// Set the initial UI for the window.
}
}
- (void)handleScreenDidDisconnectNotification:(NSNotification*)aNotification
{
if (self.secondWindow)
{
// Hide and then delete the window.
self.secondWindow.hidden = YES;
self.secondWindow = nil;
}
}
在我希望允许在 Apple TV 上镜像 WebView 的 viewController 中,我有:
- (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;
appDelegate.secondWindow = [[UIWindow alloc] initWithFrame:screenBounds];
appDelegate.secondWindow.screen = secondScreen;
// Set up initial content to display...
// Show the window.
appDelegate.secondWindow.hidden = NO;
NSLog(@"YES");
}
}
我从here 得到了这一切。但是,这就是它所显示的全部内容,所以我不确定如何将内容显示到该屏幕上。
【问题讨论】:
-
您有没有想出解决方案?我现在正在尝试做同样的事情。
-
@Daniel 不幸的是,我没有。我已经求助于让人们进行空中播放屏幕镜像,这几乎没有那么优雅或有用,但是哦,好吧。 5000 次浏览都想不通。
标签: ios uiwindow gnu-screen airplay apple-tv