airplay的问题 - 外部屏幕覆盖主屏幕

时间:2012-07-14 23:34:57

标签: iphone objective-c ios xcode uiviewcontroller

我正在尝试创建一个非常简单的应用程序来测试airplay镜像和分屏。我的主视图控制器有一个开关,假设在镜像模式和分屏模式之间切换,所有这一切都在系统基座上启用镜像后(所以首先 - 在主基座上启用镜像,然后使用开关从镜像模式切换到分割来自应用程序的屏幕模式)。第一个开关工作正常 - 我在Apple TV上看到新的寡妇,设备屏幕保持不变。再次切换,导致外部视图出现在设备屏幕上。此时,由于切换不再存在,我无能为力......(为了练习,外部屏幕只是一个空白屏幕。)

任何人都可以帮助我理解我做错了什么吗?我很确定它有点小,但如果我完全离开,我也不会感到惊讶......:/

我的一些代码:

的AppDelegate:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}

viewcontroller.m:

从viewDidLoad调用screenDidChange。点击开关时会调用switchAction。

 - (void)screenDidChange:(NSNotification *)notification
 {

NSArray *screens;
screens = [UIScreen screens];
NSUInteger screenCount = [screens count];

if (screenCount > 1) 
{
    self.extScreen = [screens objectAtIndex:1];    
}
else 
{
    // Release external screen and window
    self.extScreen = nil;
    self.mainWindow = nil;
    [self externalWindow:self.mainWindow];
}
}


- (IBAction)switchAction:(id)sender {

NSArray *screens;
screens = [UIScreen screens];
NSUInteger screenCount = [screens count];



if ([sender isOn] == YES)
{
    //Mirror mode
    self.extScreen = [screens objectAtIndex:1]; 
    [mainWindow makeKeyAndVisible];
}
else {
    //Split Screen mode
    self.extScreen = [screens objectAtIndex:0];
    [mainWindow makeKeyAndVisible];
}

self.extWindow2.hidden = NO;


if (extWindow2 == nil || !CGRectEqualToRect(extWindow2.bounds, [extScreen bounds])) 
{
    extWindow2 = [[UIWindow alloc] initWithFrame:[extScreen bounds]];
    extWindow2.screen = extScreen;
    UIView *view = [[UIView alloc] initWithFrame:[extWindow2 frame]];
    view.backgroundColor = [UIColor blueColor];
    [extWindow2 addSubview:view];
    [extWindow2 makeKeyAndVisible];

}
}

0 个答案:

没有答案