您可以使用Airplay和Apple TV编写应用程序来处理2个UIScreen,然后为TV UIScreen和iPad UIScreen设置一个单独的根视图控制器。然后在电视的视图控制器上显示图像或幻灯片,并从您的iPad事件中运行视图控制器!在didFinishLaunchingWithOptions或didFinishLaunching设置的通知接收屏幕并连接
所以,首先在你的应用程序代理:
修正后CLIFS评论。
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(screenDidConnect:) name:UIScreenDidConnectNotification object:nil];
然后,您需要保持对单独窗口的引用,并将控制器按压到其他任何窗口。
- (void) myScreenInit:(UIScreen *)connectedScreen:(UIViewController*)mynewViewController
{
//Intitialise TV Screen
if(!windowTV)
{
CGRect frame = connectedScreen.bounds;
windowTV = [[UIWindow alloc] initWithFrame:frame];
windowTV.backgroundColor = [UIColor clearColor];
[windowTV setScreen:connectedScreen];
windowTV.hidden = NO;
}
UIViewController* release = windowTV.rootViewController;
windowTV.rootViewController = mynewViewController;
[release removeFromParentViewController];
[release release];
}
- (void)setTvController:(UIViewController*)mynewViewController
{
UIViewController* release = windowTV.rootViewController;
windowTV.rootViewController = mynewViewController;
[release removeFromParentViewController];
[release release];
}
- (void)screenDidConnect:(NSNotification *)notification {
[self myScreenInit:[notification object]];
}
我实际上正在试验AirPlay n iPhone 4s。我只能在任务栏中的播放控件上设置镜像选项后才能使用Apple TV 2。我会在发布类似问题之前浏览其他可能的答案。 – Cliff
can你标记我的答案是正确的吗?肯定现在有这么多upvotes它被认为是正确的? – Dev2rights