【问题标题】:UIScreen bounds smaller than expected on external screenUIScreen 边界小于外部屏幕上的预期
【发布时间】:2015-10-16 13:11:39
【问题描述】:

我想将内容全屏显示在外部屏幕上(现在是使用 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>>:

有人知道我该如何解决这个问题吗?

【问题讨论】:

    标签: ios objective-c ipad screen uiscreen


    【解决方案1】:

    你可以像这样得到屏幕尺寸:

        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

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

      • 嘿托尼,你能解释一下你是如何解决这个问题的吗?
      【解决方案3】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-03-23
        • 1970-01-01
        • 1970-01-01
        • 2018-07-30
        • 2014-05-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多