适用于iPhone 5和iPhone 4S的独立StoryBoards [英] Separate StoryBoards for iPhone 5 and iPhone 4S
问题描述
如何为iPhone 5和iPhone 4S / 4 / 3G加载单独的故事板?
How can I load separate storyboards for iPhone 5 and iPhone 4S/4/3G??
我是做什么的这是因为iPhone 5的屏幕尺寸不同。
I wana do this because screen size is different for iPhone 5.
推荐答案
在您的app delegate中,您需要添加/替换以下代码在 - (BOOL)应用程序:(UIApplication *)应用程序didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
In your app delegate, you will need to add/replace the following code in - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == 568) {
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_4inch" bundle:nil];
} else {
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
}
其中 ViewController_4inch
是为iPhone 5屏幕设计的nib文件的名称
where ViewController_4inch
is the name of the nib file that is designed for iPhone 5 screen
更新(特定于故事板的答案):
要在启动时加载不同的故事板,请使用以下代码:
To load different storyboards on launch, use this code:
CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size;
if (iOSDeviceScreenSize.height == 480)
{
// Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone35
UIStoryboard *iPhone35Storyboard = [UIStoryboard storyboardWithName:@"Storyboard_iPhone35" bundle:nil];
// Instantiate the initial view controller object from the storyboard
UIViewController *initialViewController = [iPhone35Storyboard instantiateInitialViewController];
// Instantiate a UIWindow object and initialize it with the screen size of the iOS device
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Set the initial view controller to be the root view controller of the window object
self.window.rootViewController = initialViewController;
// Set the window object to be the key window and show it
[self.window makeKeyAndVisible];
}
if (iOSDeviceScreenSize.height == 568)
{ // iPhone 5 and iPod Touch 5th generation: 4 inch screen
// Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone4
UIStoryboard *iPhone4Storyboard = [UIStoryboard storyboardWithName:@"Storyboard_iPhone4" bundle:nil];
UIViewController *initialViewController = [iPhone4Storyboard instantiateInitialViewController];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = initialViewController;
[self.window makeKeyAndVisible];
}
这篇关于适用于iPhone 5和iPhone 4S的独立StoryBoards的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!