您可以使用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