您不需要两个故事板来执行此操作。您可以在一个故事板中同时使用它们。对于 iphone,我们通常使用一个类 SWRevealViewController(如果您是 iOS 编码新手 ..:)) ipad 的 menu 和 splitviewcontroller。我们也可以为 ipad 使用 SWRevealViewController。这取决于您的要求。
对于通用应用,使用size Classes创建视图控制器(通常我们对通用应用使用任意高度任意宽度)。
根据需要更改这些尺寸类别并为 ipad 和 iphone 创建不同的视图控制器。在大多数情况下,任何高度任何宽度都可以完成这项工作。
创建viewcontrollers后,在appdelegate中,使用instantiateViewcontrollerWithIdentifier方法,加载需要的viewcontroller。
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// The device is an iPad running ios 3.2 or later.
}
else {
// The device is an iPhone or iPod touch.
}
为 ipad 加载 splitviewcontroller。 和用于 iPhone 的 swrevealviewcontroller。
这是核心基础知识。如果您需要更多信息,请告诉我。
编辑
您是否在故事板中看到初始 VC(viewcontroller) 处的箭头标记?此 vc 在启动屏幕后首先加载。在我的应用程序中,我有一个 iphone 和 ipad 通用的主屏幕(使用大小类如上所述)。所以我可以将此vc设置为初始VC。在这种情况下,我不必在appdelegate中做任何事情。但是如果我有一个不同的ipad主屏幕,那么我可以进行条件检查appdelegate didFinishLaunchingWithOptions
您可以像这样加载第一个屏幕。您应该按照 splitVC 教程和 swrevealcontroller 教程来设置侧边菜单。只有当第一个屏幕包含侧边菜单时,您才应该加载 SWrevealVC 或 splitViewcontroller。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UISplitViewController *split = [storyboard instantiateViewControllerWithIdentifier:@"SplitViewController"];
[AppDelegate setRootController:split storyboard:storyboard actiontype:0];
}
else if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *split = [storyboard instantiateViewControllerWithIdentifier:@"SWrevealVC"];
[AppDelegate setRootController:split storyboard:storyboard actiontype:-1];
}
return YES;
}
+(void)setRootController:(UIViewController*)controller
storyboard:(UIStoryboard*)storyboard actiontype:(int) actiontype;
{
if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad && actiontype == 0)
{
UISplitViewController *splitViewController = (UISplitViewController *)controller;
//splitViewController.presentsWithGesture = false;
UINavigationController *masterNavigationController = [splitViewController.viewControllers objectAtIndex:0];
SideMenuViewController *controller = (SideMenuViewController *)masterNavigationController.topViewController;
controller.splitViewController = splitViewController;
splitViewController.delegate = (id)controller;
}
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[UIView
transitionWithView:appDelegate.window
duration:0.5
options:UIViewAnimationOptionAllowAnimatedContent
animations:^(void) {
BOOL oldState = [UIView areAnimationsEnabled];
[UIView setAnimationsEnabled:NO];
appDelegate.window.rootViewController = controller;
[UIView setAnimationsEnabled:oldState];
}
completion:nil];
}
代码可能看起来很长,但要简单。只有你做事你才能理解逻辑。