我的应用程序在设计时仅考虑了 4 英寸显示屏。在 3.5 英寸模拟器上运行时,应用程序缺少 0.5 英寸。
那么,我的问题是如何在 Xcode 5 中为不同的屏幕尺寸设置不同的 Storyboard?
我知道在我可以使用以下代码之前:
-(void)initializeStoryBoardBasedOnScreenSize {
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone)
{ // The iOS device = iPhone or iPod Touch
CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size;
if (iOSDeviceScreenSize.height == 480)
{ // iPhone 3GS, 4, and 4S and iPod Touch 3rd and 4th generation: 3.5 inch screen (diagonally measured)
// Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone35
UIStoryboard *Main_iPhone2 = [UIStoryboard storyboardWithName:@"Main_iPhone3" bundle:nil];
// Instantiate the initial view controller object from the storyboard
UIViewController *initialViewController = [Main_iPhone2 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 (diagonally measured)
// Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone4
UIStoryboard *Main_iPhone = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
// Instantiate the initial view controller object from the storyboard
UIViewController *initialViewController = [Main_iPhone 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];
}
} else if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad)
{ // The iOS device = iPad
UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
splitViewController.delegate = (id)navigationController.topViewController;
}
}
但是与 Xcode 5 的交易,以及我认为此代码不起作用的原因是项目中的“常规”下有一个部分,该部分将 Storyboard建立为整个特定设备类型的主要 Storyboard。
所以,要么有一种不同的方式来做整个单独的 Storyboard事情,要么我在代码上做错了。该代码已放置在我的应用程序委托(delegate)中,所以不要认为我在那里有任何问题。
最佳答案
在 Xcode 5 - Storyboard 中找到这个控件。一直到左侧的按钮可在整个 Storyboard 中的 3.5 和 4 英寸 View 之间切换。希望这是你所需要的。
关于ios - 制作专为 4 英寸显示器设计的 iPhone 应用程序与 3.5 英寸兼容,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18889505/