我正在iOS上开发一个显示UISplitViewController的应用程序。 在纵向模式下,显示用于显示/隐藏主视图控制器的按钮(MenuPrincipalVC) 像这样:
然而,当我旋转视图控制器时,无论菜单是否隐藏在纵向视图上,它始终可见
我希望两个方向(横向和纵向)上的主视图具有相同的行为我希望主视图(MenuPrincipalVC)隐藏,顶部的按钮用于显示/隐藏主视图控制器,这是我的代码:
这是用于创建SplitView并显示它,masterViewController总是MenuPrincipalVC,但detailView依赖于rightViewController:
#pragma mark *** UISplitViewController methods ***
-(void)showSplitViewControllerInView:(UIView *)view
withDetailViewController:(id)rightViewController{
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"iPad" bundle: nil];
UINavigationController *leftNavController;
UINavigationController *rightNavController;
MenuPrincipalVC *leftViewController = [mainStoryboard instantiateViewControllerWithIdentifier:@"MenuPrincipalVC"];
leftViewController.title = @" ";
leftNavController = [[UINavigationController alloc] initWithRootViewController:leftViewController];
rightNavController = [[UINavigationController alloc] initWithRootViewController:rightViewController];
leftNavController.toolbarHidden = FALSE;
rightNavController.toolbarHidden = FALSE;
leftNavController.navigationBar.translucent = TRUE;
rightNavController.navigationBar.translucent = TRUE;
leftNavController.toolbar.translucent = FALSE;
rightNavController.toolbar.translucent = TRUE;
UISplitViewController *splitViewController = [[UISplitViewController alloc] init];
splitViewController.viewControllers = [NSArray arrayWithObjects:leftNavController, rightNavController, nil];
splitViewController.delegate = rightViewController;
if ([splitViewController respondsToSelector:@selector(setPresentsWithGesture:)]) {
[splitViewController setPresentsWithGesture:NO];
}
view.window.rootViewController = splitViewController;
}
#pragma -
在我的rightViewController上的我设置了以下方法:
#pragma mark - UISplitViewDelegate methods
-(void)splitViewController:(UISplitViewController *)svc
willHideViewController:(UIViewController *)aViewController
withBarButtonItem:(UIBarButtonItem *)barButtonItem
forPopoverController:(UIPopoverController *)pc{
//Grab a reference to the popover
self.popover = pc;
barButtonItem.title = [NSString fontAwesomeIconStringForEnum:FABars];
NSDictionary *textAttributes = @{NSFontAttributeName : [UIFont fontWithName:kFontAwesomeFamilyName
size:TOOLBAR_ICONS_SIZE],
NSForegroundColorAttributeName : [UIColor whiteColor]};
[barButtonItem setTitleTextAttributes:textAttributes forState:UIControlStateNormal];
UINavigationItem *navItem = self.navigationItem;
[navItem setLeftBarButtonItem:barButtonItem animated:YES];
}
-(void)splitViewController:(UISplitViewController *)svc
willShowViewController:(UIViewController *)aViewController
invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem{
//Remove the barButtonItem.
[_navBarItem setLeftBarButtonItem:nil animated:YES];
//Nil out the pointer to the popover.
_popover = nil;
}
#pragma mark -
感谢您的支持
答案 0 :(得分:3)
我所要做的就是将下一行代码添加到我的详细视图控制器中:
-(BOOL)splitViewController:(UISplitViewController *)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation{
return YES;
}
答案 1 :(得分:0)
另一个解决方案可能是简单地专门设置主视图控制器的宽度(当然,演示控制器总是可以替代奇怪的行为和难以使用的分割视图方法。)