在我的项目中,我有不同的故事板文件来支持不同的iPhone大小,这里是处理在AppDelegate中选择正确的故事板文件的代码:
#define kMain5Name @"Main5"
#define kMain4sName @"Main4s"
#define kMain6Name @"Main6"
#define kMain6plusName @"Main6plus"
if (window.frame.size.height == 568){
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:kMain5Name bundle:[NSBundle mainBundle]];
id rootViewController = [storyBoard instantiateInitialViewController];
[window setRootViewController:rootViewController];
} else if (window.frame.size.height == 480){
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:kMain4sName bundle:[NSBundle mainBundle]];
id rootViewController = [storyBoard instantiateInitialViewController];
[window setRootViewController:rootViewController];
} else if (window.frame.size.height == 667){
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:kMain6Name bundle:[NSBundle mainBundle]];
id rootViewController = [storyBoard instantiateInitialViewController];
[window setRootViewController:rootViewController];
} else if (window.frame.size.height == 736){
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:kMain6plusName bundle:[NSBundle mainBundle]];
id rootViewController = [storyBoard instantiateInitialViewController];
[window setRootViewController:rootViewController];
}
我也有背景音乐。当我运行应用程序时,它会显示一个黑屏,即使在物理设备上也可播放音乐。我尝试重置模拟器内容和设置,清理项目和评论上面的代码,我也有主界面设置在mt项目导航器中的LaunchImage(.xib),但无济于事.. 难道我做错了什么?还有另一种支持不同iPhone尺寸的方法吗?