gpt4 book ai didi

ios - 如何为 iPhone 5 切换到不同的 Storyboard?

转载 作者:IT王子 更新时间:2023-10-29 07:52:31 24 4
gpt4 key购买 nike

正如应用程序为 iPad 和 iPhone 使用不同的 Storyboard一样,我希望我的应用程序为 iPhone 5 使用不同的 Storyboard。由于 Info.plist 中没有为 iPhone 5 选择默认 Storyboard的选项,如何我以编程方式调用 Storyboard?

除非万不得已,否则我不想为此应用使用 AutoLayout。我了解如何检测用户使用的是 iPhone 5 还是其他具有相同屏幕尺寸的设备。我只需要知道如何在没有 plist 的情况下设置默认 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 *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 (diagonally measured)

// Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone4
UIStoryboard *iPhone4Storyboard = [UIStoryboard storyboardWithName:@"Storyboard_iPhone4" bundle:nil];

// Instantiate the initial view controller object from the storyboard
UIViewController *initialViewController = [iPhone4Storyboard 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;

}
}

在AppDelegate下调用这个方法ddiFinishLaunchingWithOptions:方法并且不要忘记正确命名您的 Storyboard

希望有帮助...

关于ios - 如何为 iPhone 5 切换到不同的 Storyboard?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12696242/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com