在外部屏幕上,UIScreen的界限比预期的要小

时间:2015-10-16 13:11:40

标签: ios objective-c ipad screen uiscreen

我想在全屏幕上将内容放在外部屏幕上(现在使用Air Server的MacBook Pro),平板电脑上有一个屏幕。

我正在使用https://github.com/quellish/AirPlayStoryboards中的一个例子 - 这很棒。但是,我发现两个屏幕都没有显示全屏,因为UIScreen的边界回来太小 - iPad显示的颜色稍小(letterboxed),iPad屏幕只显示屏幕的1/4左上角(原点)

知道为什么会这样吗?代码:

WP_Post

Log语句返回如下:

- (void) application:(UIApplication *)__unused application didConnectScreen:(UIScreen *) screen
{

UIStoryboard        *storyboard     = nil;
UIWindow            *screenWindow   = nil;
UIViewController    *tvViewController = nil;

// Set up external screen
UIScreen *secondaryScreen = [UIScreen screens][1];
UIScreen *primaryScreen = [UIScreen screens][0];

NSLog(@"Screen 1 (iPad): %@", primaryScreen); //print the bounds of the iPad
NSLog(@"Screen 2 (MacBook): %@:", secondaryScreen); //print the bounds and size of the MacBook

UIScreenMode *screenMode = [[secondaryScreen availableModes] lastObject];
CGRect bounds = secondaryScreen.bounds;

// Create new outputWindow
screenWindow = [[UIWindow alloc] initWithFrame:bounds];
screenWindow.screen = secondaryScreen;
screenWindow.screen.currentMode = screenMode;
[screenWindow makeKeyAndVisible];


[screenWindow setScreen:screen];

storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle bundleForClass:[self class]]];
tvViewController = [storyboard instantiateViewControllerWithIdentifier:@"TVViewController"];

[screenWindow setClipsToBounds:YES];
[screenWindow setRootViewController:tvViewController];
[screenWindow setHidden:NO];

//  // If you do not retain the window, it will go away and you will see nothing.
[[self windows] addObject:screenWindow];
}

有谁知道如何解决这个问题?

3 个答案:

答案 0 :(得分:0)

您可以获得如下屏幕尺寸:

    UIScreen *secondaryScreen = [UIScreen screens][1];
    UIScreenMode *secondaryScreenMode = [[secondaryScreen availableModes] objectAtIndex: 0];
    CGSize sizeSecendaryScreen = secondaryScreenMode.size;
    screenWindow = [[UIWindow alloc] initWithFrame:CGRectMake(0,0, sizeSecendaryScreen.width, sizeSecendaryScreen.height)];

参考:Setting UIScreen's mode / resolution

答案 1 :(得分:0)

我想出来了。这与[UIScreen mainScreen] .bounds.size有关,在iOS8中变为取向依赖。我从这篇文章中得到了线索:

Is [UIScreen mainScreen].bounds.size becoming orientation-dependent in iOS8?

答案 2 :(得分:0)

在我的情况下,没有针对我想要支持的特定分辨率的启动图像。 例如:如果你想支持iPhone5,我们需要添加iPhone5大小的发布图像。 请检查您的Xcode是否有所有必需的启动图像。 这可能是您的解决方案。就我而言,它对我有用!