【发布时间】:2015-12-03 21:52:53
【问题描述】:
我正在制作可在所有 iPhone 设备 4s、5、5s、6、6+ 和 iPad 上运行的应用程序。
如果我们选择 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 中调用了这个方法。
此代码在我的其他应用中运行良好。
【问题讨论】:
-
您为多个设备执行此操作的方式是完全错误的。考虑统一故事板方法..
-
那么我应该怎么做,这在我的其他应用程序中运行良好
-
对不同的设备配置使用大小类,这将减少代码和构建大小。
-
你能给我更多的细节或链接
-
另外,您的应用是通用的还是仅限 iPhone 的?仅限 iPhone 的应用程序将在 ipad 上以 iPhone 4 分辨率打开
标签: ios objective-c iphone ipad storyboard