UIScreen 边界小于外部屏幕上的预期
UIScreen bounds smaller than expected on external screen
我想在外接屏幕(现在是使用 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语句return如下:
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>>:
有谁知道我该如何解决这个问题?
您可以这样获取屏幕尺寸:
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
我想通了。这与 [UIScreen mainScreen].bounds.size 在 iOS8 中变得依赖方向有关。我从这个 post:
得到了线索
Is [UIScreen mainScreen].bounds.size becoming orientation-dependent in iOS8?
在我的例子中,没有我想要支持的特定分辨率的启动图像。
例如:如果要支持 iPhone5 我们需要添加 iPhone5 大小的启动图像。
请检查您的 Xcode 是否拥有所有必需的启动图像。
这可能是您的解决方案。就我而言,它对我有用!
我想在外接屏幕(现在是使用 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语句return如下:
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>>:
有谁知道我该如何解决这个问题?
您可以这样获取屏幕尺寸:
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
我想通了。这与 [UIScreen mainScreen].bounds.size 在 iOS8 中变得依赖方向有关。我从这个 post:
得到了线索Is [UIScreen mainScreen].bounds.size becoming orientation-dependent in iOS8?
在我的例子中,没有我想要支持的特定分辨率的启动图像。 例如:如果要支持 iPhone5 我们需要添加 iPhone5 大小的启动图像。 请检查您的 Xcode 是否拥有所有必需的启动图像。 这可能是您的解决方案。就我而言,它对我有用!