2

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

我正在使用来自https://github.com/quellish/AirPlayStoryboards的示例- 这很棒。但是,我发现两个屏幕都没有显示全屏,因为 UIScreen 的边界太小了——iPad 显示的小一点(信箱),iPad 屏幕只显示左上角屏幕的 1/4(起源)

知道这是为什么吗?编码:

- (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];
}

Log 语句返回如下:

Screen 1 (iPad): <UIScreen: 0x1567def0; bounds = {{0, 0}, {480, 320}}; mode = <UIScreenMode: 0x1567dd60; size = 1024.000000 x 768.000000>>

Screen 2 (MacBook): <UIScreen: 0x15680280; bounds = {{0, 0}, {640, 400}}; mode = <UIScreenMode: 0x156804a0; size = 1280.000000 x 800.000000>>:

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

4

3 回答 3

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)];

参考:设置 UIScreen 的模式/分辨率

于 2015-10-21T13:07:09.797 回答
0

我想通了。这与 [UIScreen mainScreen].bounds.size 在 iOS8 中变得依赖于方向有关。我从这篇文章中得到了线索:

[UIScreen mainScreen].bounds.size 在 iOS8 中是否变得依赖于方向?

于 2015-10-26T09:28:39.013 回答
0

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

于 2015-10-26T09:28:52.847 回答