设置UIScreen值后保持UIWindow大小

时间:2013-04-05 00:42:12

标签: uiwindow airplay uiscreen

我正在使用AirPlay,iPad的主要内容是AppleTV罚款。

当我想在iPad上获取与AppleTV不同的信息时,我会收到解决方案问题。

我实例化UIWindow:

_atvWindow = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 2048, 1536)];

NSLog表示窗口是我想要的帧大小

我将UIWindow设置为iPad屏幕

_atvWindow.screen = [[UIScreen screens] objectAtIndex:0];

NSLog表示窗口框架现在是1024x768

这是一款视网膜iPad。我希望大小保持视网膜和相应的设置图像。一旦我添加了视网膜质量的图像,它们(正如您所期望的那样)太大了。是什么原因造成了这个或我在这里缺少什么?

1 个答案:

答案 0 :(得分:0)

您是否尝试从[通知对象]对象中的屏幕读取帧大小?

- (void)handleConnectedScreen:(UIScreen *)screen withViewController:(UIViewController *)controller {
    if(!_airPlayWindow)
    {
        CGRect frame = screen.bounds;
        _airPlayWindow = [[UIWindow alloc] initWithFrame:frame];
        _airPlayWindow.backgroundColor = [UIColor clearColor];
        [_airPlayWindow setScreen:screen];
        _airPlayWindow.hidden = NO;
    }

    UIViewController *oldController = _airPlayWindow.rootViewController;
    [_airPlayWindow setRootViewController:controller];
    [oldController removeFromParentViewController];
}


- (void)screenDidConnect:(NSNotification *)notification {
    ABOutputViewController *c = [[ABOutputViewController alloc] init];
    [self handleConnectedScreen:[notification object] withViewController:c];
}


[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(screenDidConnect:) name:UIScreenDidConnectNotification object:nil];