use*_*452 6 gnu-screen uiwindow ios airplay apple-tv
我正在考虑将AirPlay功能添加到我的一个ViewControllers中.View Controller只显示一个UIWebView.我想要做的是添加一个按钮,将此内容镜像到Apple TV.我知道系统范围的镜像可以完成,但它不会填满整个屏幕,周围都是黑条.我一直在网上搜索,但我发现的大部分内容都是从iOS 5回来并且已经过时了.有人能指出我的教程或插入库的方向会有所帮助吗?我只需要在Apple TV上将一个视图的内容镜像为全屏.
到目前为止,这是我所做的,但我相信它只会创建第二个窗口,而不会在其上放置任何内容.
在AppDelegate中,我为它创建了一个属性:
@property (nonatomic, retain) UIWindow *secondWindow;
Run Code Online (Sandbox Code Playgroud)
在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];
Run Code Online (Sandbox Code Playgroud)
然后在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;
}
}
Run Code Online (Sandbox Code Playgroud)
在我想允许在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");
}
}
Run Code Online (Sandbox Code Playgroud)
我从这里得到了这一切.但是,这就是它所显示的一切,所以我不确定如何将内容放到该屏幕上.
根据 Web 视图中发生的情况,您要么必须创建第二个指向同一页面的页面,要么将现有页面移至新窗口。无论哪种方式,您对待第二个窗口的方式与对待应用程序\xe2\x80\x99s主窗口\xe2\x80\x94向其添加视图的方式几乎相同,它们应该显示在第二个显示器上。
\n| 归档时间: |
|
| 查看次数: |
5506 次 |
| 最近记录: |