iPad 屏幕尺寸 return 错误值
iPad screen size return wrong value
我正在制作可在所有 iPhone 设备 4s、5、5s、6、6+ 和 iPads..
上运行的应用
如果我们选择 iPhone 4s 模拟器,它将加载 4s 故事板。
我为不同尺寸的屏幕设计了单独的故事板。
它在所有 iPhone 设备上运行良好,但是当我在模拟器选项中选择 iPad 时,它会给我 iPhone 4s 屏幕。
这是在 AppDelegate 中根据屏幕大小加载不同故事板的代码。
- (UIStoryboard *)grabStoryboard
{
// determine screen size
int screenHeight = [UIScreen mainScreen].bounds.size.height;
NSLog(@"screenHeight:-%d",screenHeight);///here it it gives me 480 in iPad so it goes in case 480.
UIStoryboard *storyboard;
switch (screenHeight)
{
// iPhone 4s
case 480:
storyboard = [UIStoryboard storyboardWithName:@"Main-4s" bundle:nil];
break;
// iPhone 5s
case 568:
storyboard = [UIStoryboard storyboardWithName:@"Main-5s" bundle:nil];
break;
// iPhone 6
case 667:
storyboard = [UIStoryboard storyboardWithName:@"Main-6" bundle:nil];
break;
// iPhone 6 Plus
case 736:
storyboard = [UIStoryboard storyboardWithName:@"Main-6Plus" bundle:nil];
break;
default:
// it's an iPad
storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
break;
}
return storyboard;
}
并在 didFinishLaunchingWithOptions 中调用了这个方法。
此代码在我的其他应用中运行良好。
无需为每个分辨率配置单独的故事板。在 Xcode 中,您可以通过 Interface Builder 为不同的屏幕尺寸配置布局。在底部,您可以更改各种屏幕尺寸的约束条件。
Here's a brief tutorial 这应该会让你指向正确的方向。
您的应用已在 iPad 中放大到 iPhone 的分辨率 4. 您需要将目标设备设置为通用。
我正在制作可在所有 iPhone 设备 4s、5、5s、6、6+ 和 iPads..
上运行的应用如果我们选择 iPhone 4s 模拟器,它将加载 4s 故事板。 我为不同尺寸的屏幕设计了单独的故事板。
它在所有 iPhone 设备上运行良好,但是当我在模拟器选项中选择 iPad 时,它会给我 iPhone 4s 屏幕。
这是在 AppDelegate 中根据屏幕大小加载不同故事板的代码。
- (UIStoryboard *)grabStoryboard
{
// determine screen size
int screenHeight = [UIScreen mainScreen].bounds.size.height;
NSLog(@"screenHeight:-%d",screenHeight);///here it it gives me 480 in iPad so it goes in case 480.
UIStoryboard *storyboard;
switch (screenHeight)
{
// iPhone 4s
case 480:
storyboard = [UIStoryboard storyboardWithName:@"Main-4s" bundle:nil];
break;
// iPhone 5s
case 568:
storyboard = [UIStoryboard storyboardWithName:@"Main-5s" bundle:nil];
break;
// iPhone 6
case 667:
storyboard = [UIStoryboard storyboardWithName:@"Main-6" bundle:nil];
break;
// iPhone 6 Plus
case 736:
storyboard = [UIStoryboard storyboardWithName:@"Main-6Plus" bundle:nil];
break;
default:
// it's an iPad
storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
break;
}
return storyboard;
}
并在 didFinishLaunchingWithOptions 中调用了这个方法。
此代码在我的其他应用中运行良好。
无需为每个分辨率配置单独的故事板。在 Xcode 中,您可以通过 Interface Builder 为不同的屏幕尺寸配置布局。在底部,您可以更改各种屏幕尺寸的约束条件。
Here's a brief tutorial 这应该会让你指向正确的方向。
您的应用已在 iPad 中放大到 iPhone 的分辨率 4. 您需要将目标设备设置为通用。