Reputation: 8586
I am developing an app on iOS which displays a UISplitViewController. On portrait mode shows a button for showing/hidding the masterview controller (MenuPrincipalVC) like this:
However when I rotate the view controller no matter if the menu was hidden on portrait view, it's always visible
I want the same behavior for master view on both orientations (landscape and portrait) I want the master view (MenuPrincipalVC) hidden and a button on the top for showing /hidding master view controller, this is my code:
This is for creating the SplitView and displaying it, masterViewController is always MenuPrincipalVC, but detailView depends of 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 -
on my rightViewController I set the following Methods:
#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 -
thanks for the support
Upvotes: 2
Views: 1129
Reputation: 1527
Another solution may be to simply to specifically set the width of the master view controller (and, of course, presentation controllers can always substitute the oddly behaving and difficult-to-use split-view approach).
Upvotes: 0
Reputation: 8586
all I had to do is to add next line of code to my detailed view controller:
-(BOOL)splitViewController:(UISplitViewController *)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation{
return YES;
}
Upvotes: 3