如何在iOS中以纵向模式实现SplitView功能?
我正在尝试在iOS应用程序中实现SplitView功能,它只有在iPad设备的横向模式下才能正常工作 如果启动应用程序或将其从横向模式旋转到纵向模式,splitView功能将崩溃 如何在iPhone(纵向和横向)和iPad(纵向模式)设备中实现SplitView功能 请在代码下面找到我的代码如何在iOS中以纵向模式实现SplitView功能?,ios,iphone,ipad,uisplitviewcontroller,master-detail,Ios,Iphone,Ipad,Uisplitviewcontroller,Master Detail,我正在尝试在iOS应用程序中实现SplitView功能,它只有在iPad设备的横向模式下才能正常工作 如果启动应用程序或将其从横向模式旋转到纵向模式,splitView功能将崩溃 如何在iPhone(纵向和横向)和iPad(纵向模式)设备中实现SplitView功能 请在代码下面找到我的代码 - (BOOL)application:(UIApplication *)applicationdidFinishLaunchingWithOptions:(NSDictionary *)launchOpt
- (BOOL)application:(UIApplication *)applicationdidFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen]bounds]];
UITabBarController *tabBarController = [[UITabBarController alloc] init];
ViewController *masterViewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
UINavigationController *masterNavigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
DetailViewController *detailViewController = [[DetailViewController alloc]initWithNibName:@"DetailViewController"
bundle:nil];
UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController];
masterViewController.detailViewController = detailViewController;
self.splitViewController = [[CustomSplitViewController alloc]initWithNibName:@"CustomSplitViewController" bundle:nil];
self.splitViewController.viewControllers = @[masterNavigationController, detailNavigationController];
TabBarDetailController *secondVC = [[TabBarDetailController alloc]initWithNibName:@"TabBarDetailController" bundle:nil];
secondVC.tabBarItem.title = @"Second";
ThirdViewController *thirdVC = [[ThirdViewController alloc]initWithNibName:@"ThirdViewController" bundle:nil];
thirdVC.tabBarItem.title = @"Third";
FourthViewController *fourthVC = [[FourthViewController alloc]initWithNibName:@"FourthViewController" bundle:nil];
fourthVC.tabBarItem.title = @"Fourth";
MoreViewController *moreVC = [[MoreViewController alloc]initWithNibName:@"MoreViewController" bundle:nil];
moreVC.tabBarItem.title = @"More";
//make an array containing view controllers
NSArray *viewControllers = [NSArray arrayWithObjects:self.splitViewController,secondVC,thirdVC,fourthVC,moreVC,nil];
[tabBarController setViewControllers:viewControllers];
self.splitViewController.tabBarItem.title = @"HOME";
[self.window addSubview:tabBarController.view];
self.window.rootViewController=tabBarController;
[[self window] makeKeyAndVisible];
return YES;
}
提前谢谢。
您看过
。首选显示模式?UISplitViewController
基于大小类。从iOS 14开始(甚至可能是13),这意味着纵向的iPhone将始终显示您设置为紧凑型VC的内容,横向的iPhone将显示次要(4种尺寸)或紧凑型(6种尺寸)。至于ipad呢?不考虑真正的“分割屏幕”——即屏幕上有多个应用程序,它应该始终显示第二个VC,无论方向如何。我不知道你为什么在iPad上看到不同的东西。我最好的猜测是你的“根”VC层次结构,它看起来像是标签栏在根上。